Add transmission dashboard to grafana

- Add node_exporter ansible role to enable textfile collector
- Add transmission_metrics role with script and LaunchAgent
  - Collects metrics every 60s via transmission RPC
  - Writes to /opt/homebrew/var/node_exporter/textfile/transmission.prom
- Update grafana role to provision dashboards from files
- Add transmission.json dashboard with:
  - Status indicator, torrent counts
  - Transfer speeds, cumulative stats
  - Time series graphs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Erich Blume 2026-01-14 13:46:51 -08:00
commit 7468023cd2
15 changed files with 814 additions and 1 deletions

View file

@ -2,7 +2,9 @@
"permissions": {
"allow": [
"Bash(mcquack --help:*)",
"Bash(tea help:*)"
"Bash(tea help:*)",
"Bash(git add:*)",
"Bash(git commit:*)"
]
}
}

View file

@ -2,12 +2,16 @@
- name: Configure indri
hosts: indri
roles:
- role: node_exporter
tags: node_exporter
- role: prometheus
tags: prometheus
- role: grafana
tags: grafana
- role: transmission
tags: transmission
- role: transmission_metrics
tags: transmission_metrics
- role: kiwix
tags: kiwix
- role: borgmatic

View file

@ -0,0 +1,592 @@
{
"annotations": {
"list": []
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": null,
"links": [],
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "red", "value": null},
{"color": "green", "value": 1}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {"h": 4, "w": 4, "x": 0, "y": 0},
"id": 1,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_up",
"refId": "A"
}
],
"title": "Transmission Status",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "green", "value": null}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {"h": 4, "w": 4, "x": 4, "y": 0},
"id": 2,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_torrents_total",
"refId": "A"
}
],
"title": "Total Torrents",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "blue", "value": null}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {"h": 4, "w": 4, "x": 8, "y": 0},
"id": 3,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_torrents_active",
"refId": "A"
}
],
"title": "Active Torrents",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "orange", "value": null}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {"h": 4, "w": 4, "x": 12, "y": 0},
"id": 4,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_torrents_paused",
"refId": "A"
}
],
"title": "Paused Torrents",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "green", "value": null}
]
},
"unit": "decbytes"
},
"overrides": []
},
"gridPos": {"h": 4, "w": 4, "x": 16, "y": 0},
"id": 5,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_downloaded_bytes_total",
"refId": "A"
}
],
"title": "Total Downloaded",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "purple", "value": null}
]
},
"unit": "decbytes"
},
"overrides": []
},
"gridPos": {"h": 4, "w": 4, "x": 20, "y": 0},
"id": 6,
"options": {
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_uploaded_bytes_total",
"refId": "A"
}
],
"title": "Total Uploaded",
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "green", "value": null}
]
},
"unit": "Bps"
},
"overrides": [
{
"matcher": {"id": "byName", "options": "Download"},
"properties": [
{"id": "color", "value": {"fixedColor": "green", "mode": "fixed"}}
]
},
{
"matcher": {"id": "byName", "options": "Upload"},
"properties": [
{"id": "color", "value": {"fixedColor": "blue", "mode": "fixed"}}
]
}
]
},
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 4},
"id": 7,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_download_speed_bytes",
"legendFormat": "Download",
"refId": "A"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_upload_speed_bytes",
"legendFormat": "Upload",
"refId": "B"
}
],
"title": "Transfer Speed",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "green", "value": null}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 4},
"id": 8,
"options": {
"legend": {
"calcs": ["mean", "max"],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_torrents_total",
"legendFormat": "Total",
"refId": "A"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_torrents_active",
"legendFormat": "Active",
"refId": "B"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "transmission_torrents_paused",
"legendFormat": "Paused",
"refId": "C"
}
],
"title": "Torrent Count",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{"color": "green", "value": null}
]
},
"unit": "Bps"
},
"overrides": [
{
"matcher": {"id": "byName", "options": "Download Rate"},
"properties": [
{"id": "color", "value": {"fixedColor": "green", "mode": "fixed"}}
]
},
{
"matcher": {"id": "byName", "options": "Upload Rate"},
"properties": [
{"id": "color", "value": {"fixedColor": "blue", "mode": "fixed"}}
]
}
]
},
"gridPos": {"h": 8, "w": 24, "x": 0, "y": 12},
"id": 9,
"options": {
"legend": {
"calcs": ["mean", "max", "lastNotNull"],
"displayMode": "table",
"placement": "right",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "10.0.0",
"targets": [
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "rate(transmission_downloaded_bytes_total[5m])",
"legendFormat": "Download Rate",
"refId": "A"
},
{
"datasource": {"type": "prometheus", "uid": "prometheus"},
"expr": "rate(transmission_uploaded_bytes_total[5m])",
"legendFormat": "Upload Rate",
"refId": "B"
}
],
"title": "Cumulative Transfer Rate (5m avg)",
"type": "timeseries"
}
],
"refresh": "30s",
"schemaVersion": 38,
"tags": ["transmission", "bittorrent"],
"templating": {
"list": []
},
"time": {
"from": "now-6h",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "Transmission",
"uid": "transmission",
"version": 1,
"weekStart": ""
}

View file

@ -28,6 +28,20 @@
mode: '0644'
notify: restart grafana
- name: Deploy grafana dashboards provider config
ansible.builtin.template:
src: dashboards.yaml.j2
dest: /opt/homebrew/etc/grafana/provisioning/dashboards/default.yaml
mode: '0644'
notify: restart grafana
- name: Deploy grafana dashboard JSON files
ansible.builtin.copy:
src: "dashboards/"
dest: /opt/homebrew/etc/grafana/provisioning/dashboards/
mode: '0644'
notify: restart grafana
- name: Ensure grafana service is started
ansible.builtin.command: brew services start grafana
register: brew_start

View file

@ -0,0 +1,12 @@
# {{ ansible_managed }}
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
editable: true
options:
path: /opt/homebrew/etc/grafana/provisioning/dashboards

View file

@ -0,0 +1,2 @@
---
node_exporter_textfile_dir: /opt/homebrew/var/node_exporter/textfile

View file

@ -0,0 +1,4 @@
---
- name: restart node_exporter
ansible.builtin.command: brew services restart node_exporter
listen: restart node_exporter

View file

@ -0,0 +1,22 @@
---
# Note: node_exporter is installed via homebrew manually.
# This role manages the args file to enable textfile collector.
- name: Create textfile collector directory
ansible.builtin.file:
path: "{{ node_exporter_textfile_dir }}"
state: directory
mode: '0755'
- name: Configure node_exporter args
ansible.builtin.template:
src: node_exporter.args.j2
dest: /opt/homebrew/etc/node_exporter.args
mode: '0644'
notify: restart node_exporter
- name: Ensure node_exporter service is started
ansible.builtin.command: brew services start node_exporter
register: brew_start
changed_when: "'Successfully started' in brew_start.stdout"
failed_when: false

View file

@ -0,0 +1 @@
--collector.textfile.directory={{ node_exporter_textfile_dir }}

View file

@ -0,0 +1,7 @@
---
transmission_rpc_host: 127.0.0.1
transmission_rpc_port: 9091
transmission_metrics_dir: /opt/homebrew/var/node_exporter/textfile
transmission_metrics_script: /opt/homebrew/bin/transmission-metrics
transmission_metrics_interval: 60 # seconds between metric collection
transmission_log_dir: /opt/homebrew/var/log

View file

@ -0,0 +1,5 @@
---
- name: reload transmission-metrics
ansible.builtin.shell: |
launchctl unload ~/Library/LaunchAgents/mcquack.eblume.transmission-metrics.plist 2>/dev/null || true
launchctl load ~/Library/LaunchAgents/mcquack.eblume.transmission-metrics.plist

View file

@ -0,0 +1,4 @@
---
dependencies:
- role: node_exporter
- role: transmission

View file

@ -0,0 +1,20 @@
---
- name: Deploy transmission metrics collection script
ansible.builtin.template:
src: transmission-metrics.sh.j2
dest: "{{ transmission_metrics_script }}"
mode: '0755'
notify: reload transmission-metrics
- name: Deploy transmission-metrics LaunchAgent plist
ansible.builtin.template:
src: transmission-metrics.plist.j2
dest: ~/Library/LaunchAgents/mcquack.eblume.transmission-metrics.plist
mode: '0644'
notify: reload transmission-metrics
- name: Ensure transmission-metrics LaunchAgent is loaded
ansible.builtin.command: launchctl load ~/Library/LaunchAgents/mcquack.eblume.transmission-metrics.plist
register: launchctl_load
changed_when: launchctl_load.rc == 0
failed_when: false

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- {{ ansible_managed }} -->
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>mcquack.eblume.transmission-metrics</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/opt/homebrew/bin:/usr/bin:/bin</string>
</dict>
<key>ProgramArguments</key>
<array>
<string>{{ transmission_metrics_script }}</string>
</array>
<key>StartInterval</key>
<integer>{{ transmission_metrics_interval }}</integer>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>{{ transmission_log_dir }}/transmission-metrics.err.log</string>
<key>StandardOutPath</key>
<string>{{ transmission_log_dir }}/transmission-metrics.out.log</string>
</dict>
</plist>

View file

@ -0,0 +1,98 @@
#!/bin/bash
# {{ ansible_managed }}
# Collects transmission-daemon metrics for node_exporter textfile collector
set -euo pipefail
RPC_URL="http://{{ transmission_rpc_host }}:{{ transmission_rpc_port }}/transmission/rpc"
OUTPUT_FILE="{{ transmission_metrics_dir }}/transmission.prom"
TEMP_FILE="${OUTPUT_FILE}.tmp"
# Get session ID (required for transmission RPC)
get_session_id() {
curl -s -I "$RPC_URL" 2>/dev/null | grep -i 'X-Transmission-Session-Id' | awk '{print $2}' | tr -d '\r'
}
# Make RPC request
rpc_request() {
local method="$1"
local session_id
session_id=$(get_session_id)
if [ -z "$session_id" ]; then
echo "Failed to get session ID" >&2
return 1
fi
curl -s "$RPC_URL" \
-H "X-Transmission-Session-Id: $session_id" \
-H "Content-Type: application/json" \
-d "{\"method\": \"$method\"}"
}
# Get session stats
session_stats=$(rpc_request "session-stats")
if [ -z "$session_stats" ] || ! echo "$session_stats" | grep -q '"result":"success"'; then
echo "Failed to get session stats" >&2
exit 1
fi
# Extract values using grep/sed (avoiding jq dependency)
extract_json_int() {
echo "$1" | grep -o "\"$2\":[0-9]*" | head -1 | sed "s/\"$2\"://"
}
# Session stats
download_speed=$(extract_json_int "$session_stats" "downloadSpeed")
upload_speed=$(extract_json_int "$session_stats" "uploadSpeed")
torrents_active=$(extract_json_int "$session_stats" "activeTorrentCount")
torrents_paused=$(extract_json_int "$session_stats" "pausedTorrentCount")
torrents_total=$(extract_json_int "$session_stats" "torrentCount")
# Cumulative stats
downloaded_bytes=$(echo "$session_stats" | grep -o '"cumulative-stats":{[^}]*}' | grep -o '"downloadedBytes":[0-9]*' | sed 's/"downloadedBytes"://')
uploaded_bytes=$(echo "$session_stats" | grep -o '"cumulative-stats":{[^}]*}' | grep -o '"uploadedBytes":[0-9]*' | sed 's/"uploadedBytes"://')
seconds_active=$(echo "$session_stats" | grep -o '"cumulative-stats":{[^}]*}' | grep -o '"secondsActive":[0-9]*' | sed 's/"secondsActive"://')
# Write metrics
cat > "$TEMP_FILE" << EOF
# HELP transmission_download_speed_bytes Current download speed in bytes per second
# TYPE transmission_download_speed_bytes gauge
transmission_download_speed_bytes ${download_speed:-0}
# HELP transmission_upload_speed_bytes Current upload speed in bytes per second
# TYPE transmission_upload_speed_bytes gauge
transmission_upload_speed_bytes ${upload_speed:-0}
# HELP transmission_torrents_active Number of active torrents
# TYPE transmission_torrents_active gauge
transmission_torrents_active ${torrents_active:-0}
# HELP transmission_torrents_paused Number of paused torrents
# TYPE transmission_torrents_paused gauge
transmission_torrents_paused ${torrents_paused:-0}
# HELP transmission_torrents_total Total number of torrents
# TYPE transmission_torrents_total gauge
transmission_torrents_total ${torrents_total:-0}
# HELP transmission_downloaded_bytes_total Total bytes downloaded (cumulative)
# TYPE transmission_downloaded_bytes_total counter
transmission_downloaded_bytes_total ${downloaded_bytes:-0}
# HELP transmission_uploaded_bytes_total Total bytes uploaded (cumulative)
# TYPE transmission_uploaded_bytes_total counter
transmission_uploaded_bytes_total ${uploaded_bytes:-0}
# HELP transmission_seconds_active_total Total seconds transmission has been active
# TYPE transmission_seconds_active_total counter
transmission_seconds_active_total ${seconds_active:-0}
# HELP transmission_up Transmission daemon is up and responding
# TYPE transmission_up gauge
transmission_up 1
EOF
# Atomic move
mv "$TEMP_FILE" "$OUTPUT_FILE"