Add total torrent size metric and dashboard panel
- Query torrent-get RPC to sum totalSize of all torrents - Add transmission_torrents_size_bytes gauge metric - Add "Total Torrent Size" timeseries panel to dashboard Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d18c3a6f3c
commit
e264b39cd6
2 changed files with 101 additions and 1 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue