diff --git a/ansible/roles/grafana/files/dashboards/transmission.json b/ansible/roles/grafana/files/dashboards/transmission.json index 7d1b28c..89c516d 100644 --- a/ansible/roles/grafana/files/dashboards/transmission.json +++ b/ansible/roles/grafana/files/dashboards/transmission.json @@ -571,6 +571,86 @@ ], "title": "Cumulative Transfer Rate (5m avg)", "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "fixed", + "fixedColor": "semi-dark-purple" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 20, + "gradientMode": "opacity", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + {"color": "green", "value": null} + ] + }, + "unit": "decbytes" + }, + "overrides": [] + }, + "gridPos": {"h": 8, "w": 24, "x": 0, "y": 20}, + "id": 10, + "options": { + "legend": { + "calcs": ["lastNotNull", "min", "max"], + "displayMode": "table", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "10.0.0", + "targets": [ + { + "datasource": {"type": "prometheus", "uid": "prometheus"}, + "expr": "transmission_torrents_size_bytes", + "legendFormat": "Total Torrent Size", + "refId": "A" + } + ], + "title": "Total Torrent Size", + "type": "timeseries" } ], "refresh": "30s", diff --git a/ansible/roles/transmission_metrics/templates/transmission-metrics.sh.j2 b/ansible/roles/transmission_metrics/templates/transmission-metrics.sh.j2 index 2916b27..8eb12a0 100644 --- a/ansible/roles/transmission_metrics/templates/transmission-metrics.sh.j2 +++ b/ansible/roles/transmission_metrics/templates/transmission-metrics.sh.j2 @@ -18,6 +18,7 @@ get_session_id() { # Make RPC request rpc_request() { local method="$1" + local args="${2:-}" local session_id session_id=$(get_session_id) @@ -26,10 +27,17 @@ rpc_request() { return 1 fi + local payload + if [ -n "$args" ]; then + payload="{\"method\": \"$method\", \"arguments\": $args}" + else + payload="{\"method\": \"$method\"}" + fi + curl -s "$RPC_URL" \ -H "X-Transmission-Session-Id: $session_id" \ -H "Content-Type: application/json" \ - -d "{\"method\": \"$method\"}" + -d "$payload" } # Get session stats @@ -57,6 +65,14 @@ downloaded_bytes=$(echo "$session_stats" | grep -o '"cumulative-stats":{[^}]*}' 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"://') +# Get total size of all torrents +torrent_info=$(rpc_request "torrent-get" '{"fields": ["totalSize"]}') +total_size_bytes=0 +if echo "$torrent_info" | grep -q '"result":"success"'; then + # Sum all totalSize values + total_size_bytes=$(echo "$torrent_info" | grep -o '"totalSize":[0-9]*' | sed 's/"totalSize"://' | awk '{sum += $1} END {print sum}') +fi + # Write metrics cat > "$TEMP_FILE" << EOF # HELP transmission_download_speed_bytes Current download speed in bytes per second @@ -79,6 +95,10 @@ transmission_torrents_paused ${torrents_paused:-0} # TYPE transmission_torrents_total gauge transmission_torrents_total ${torrents_total:-0} +# HELP transmission_torrents_size_bytes Total size of all torrents in bytes +# TYPE transmission_torrents_size_bytes gauge +transmission_torrents_size_bytes ${total_size_bytes:-0} + # HELP transmission_downloaded_bytes_total Total bytes downloaded (cumulative) # TYPE transmission_downloaded_bytes_total counter transmission_downloaded_bytes_total ${downloaded_bytes:-0}