From 61dced048b863c031f7b7647726c0ff84d12ab21 Mon Sep 17 00:00:00 2001 From: Erich Blume Date: Sun, 18 Jan 2026 14:57:35 -0800 Subject: [PATCH] Fix borgmatic-metrics script PATH issue (#28) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Fixed borgmatic-metrics script failing in LaunchAgent context - Changed from `mise x -- borg` to absolute paths (`/opt/homebrew/bin/borg`, `/opt/homebrew/bin/jq`) - This fixes the Grafana dashboard showing "DOWN" for Repository Status and missing time series data ## Deployment and Testing - [ ] Run `mise run provision-indri -- --tags borgmatic-metrics` to deploy the fix - [ ] Wait for the hourly metrics collection (or manually run `ssh indri '~/bin/borgmatic-metrics'`) - [ ] Verify Grafana dashboard shows "UP" status and populated graphs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: https://forge.tail8d86e.ts.net/eblume/blumeops/pulls/28 --- .../templates/borgmatic-metrics.sh.j2 | 35 ++++++++++--------- .../grafana/files/dashboards/borgmatic.json | 2 +- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ansible/roles/borgmatic_metrics/templates/borgmatic-metrics.sh.j2 b/ansible/roles/borgmatic_metrics/templates/borgmatic-metrics.sh.j2 index 99ce1ca..856cbe9 100644 --- a/ansible/roles/borgmatic_metrics/templates/borgmatic-metrics.sh.j2 +++ b/ansible/roles/borgmatic_metrics/templates/borgmatic-metrics.sh.j2 @@ -9,8 +9,9 @@ BORG_REPO="{{ borgmatic_metrics_repo }}" OUTPUT_FILE="{{ borgmatic_metrics_dir }}/borgmatic.prom" TEMP_FILE="${OUTPUT_FILE}.tmp" -# Check if borg is available via mise -BORG_CMD="mise x -- borg" +# Use absolute paths for LaunchAgent compatibility +BORG_CMD="/opt/homebrew/bin/borg" +JQ_CMD="/opt/homebrew/bin/jq" # Get repository info repo_json=$($BORG_CMD info --json "$BORG_REPO" 2>/dev/null) || { @@ -32,18 +33,18 @@ archives_json=$($BORG_CMD list --json "$BORG_REPO" 2>/dev/null) || { } # Extract repository stats -total_size=$(echo "$repo_json" | jq -r '.cache.stats.total_size') -total_csize=$(echo "$repo_json" | jq -r '.cache.stats.total_csize') -unique_size=$(echo "$repo_json" | jq -r '.cache.stats.unique_size') -unique_csize=$(echo "$repo_json" | jq -r '.cache.stats.unique_csize') -total_chunks=$(echo "$repo_json" | jq -r '.cache.stats.total_chunks') -unique_chunks=$(echo "$repo_json" | jq -r '.cache.stats.total_unique_chunks') +total_size=$(echo "$repo_json" | $JQ_CMD -r '.cache.stats.total_size') +total_csize=$(echo "$repo_json" | $JQ_CMD -r '.cache.stats.total_csize') +unique_size=$(echo "$repo_json" | $JQ_CMD -r '.cache.stats.unique_size') +unique_csize=$(echo "$repo_json" | $JQ_CMD -r '.cache.stats.unique_csize') +total_chunks=$(echo "$repo_json" | $JQ_CMD -r '.cache.stats.total_chunks') +unique_chunks=$(echo "$repo_json" | $JQ_CMD -r '.cache.stats.total_unique_chunks') # Count archives -archive_count=$(echo "$archives_json" | jq -r '.archives | length') +archive_count=$(echo "$archives_json" | $JQ_CMD -r '.archives | length') # Get last archive info -last_archive_name=$(echo "$archives_json" | jq -r '.archives[-1].name // empty') +last_archive_name=$(echo "$archives_json" | $JQ_CMD -r '.archives[-1].name // empty') if [ -n "$last_archive_name" ]; then # Get detailed info for the last archive @@ -53,13 +54,13 @@ if [ -n "$last_archive_name" ]; then } if [ -n "$last_archive_json" ]; then - last_original_size=$(echo "$last_archive_json" | jq -r '.archives[0].stats.original_size') - last_compressed_size=$(echo "$last_archive_json" | jq -r '.archives[0].stats.compressed_size') - last_deduplicated_size=$(echo "$last_archive_json" | jq -r '.archives[0].stats.deduplicated_size') - last_nfiles=$(echo "$last_archive_json" | jq -r '.archives[0].stats.nfiles') - last_start=$(echo "$last_archive_json" | jq -r '.archives[0].start') - last_end=$(echo "$last_archive_json" | jq -r '.archives[0].end') - last_duration=$(echo "$last_archive_json" | jq -r '.archives[0].duration') + last_original_size=$(echo "$last_archive_json" | $JQ_CMD -r '.archives[0].stats.original_size') + last_compressed_size=$(echo "$last_archive_json" | $JQ_CMD -r '.archives[0].stats.compressed_size') + last_deduplicated_size=$(echo "$last_archive_json" | $JQ_CMD -r '.archives[0].stats.deduplicated_size') + last_nfiles=$(echo "$last_archive_json" | $JQ_CMD -r '.archives[0].stats.nfiles') + last_start=$(echo "$last_archive_json" | $JQ_CMD -r '.archives[0].start') + last_end=$(echo "$last_archive_json" | $JQ_CMD -r '.archives[0].end') + last_duration=$(echo "$last_archive_json" | $JQ_CMD -r '.archives[0].duration') # Convert timestamp to unix epoch last_timestamp=$(date -j -f "%Y-%m-%dT%H:%M:%S" "${last_start%.*}" "+%s" 2>/dev/null || echo "0") diff --git a/ansible/roles/grafana/files/dashboards/borgmatic.json b/ansible/roles/grafana/files/dashboards/borgmatic.json index d2233ed..7308448 100644 --- a/ansible/roles/grafana/files/dashboards/borgmatic.json +++ b/ansible/roles/grafana/files/dashboards/borgmatic.json @@ -496,7 +496,7 @@ }, "overrides": [] }, - "gridPos": { "h": 8, "w": 8, "x": 16, "y": 4 }, + "gridPos": { "h": 8, "w": 12, "x": 0, "y": 24 }, "id": 14, "options": { "displayMode": "basic",