Skip to content

Instantly share code, notes, and snippets.

@droM4X
Last active June 24, 2023 17:58
Show Gist options
  • Save droM4X/4cbc10994d586a29682b67cc00f2d342 to your computer and use it in GitHub Desktop.
Save droM4X/4cbc10994d586a29682b67cc00f2d342 to your computer and use it in GitHub Desktop.
Collectd - Qbittorrent stats + current speeds // Qbittorrent v4.1+
#!/bin/bash
HOSTNAME=${COLLECTD_HOSTNAME:-localhost};
INTERVAL=${COLLECTD_INTERVAL:-60};
while sleep "$INTERVAL"
do
for filter in active all downloading
do
url="http://localhost:8080/api/v2/torrents/info?filter=$filter"
count=$(curl -s $url | jq length)
echo "PUTVAL \"$HOSTNAME/exec-qbittorrent/gauge-$filter\" interval=$INTERVAL N:$count"
done
url="http://localhost:8080/api/v2/torrents/info?filter=active"
dlspeed=$(curl -s $url | jq '.[].dlspeed' | awk 'NF{sum+=$1} END {print sum}')
upspeed=$(curl -s $url | jq '.[].upspeed' | awk 'NF{sum+=$1} END {print sum}')
echo "PUTVAL \"$HOSTNAME/exec-qbittorrent-speeds/gauge-dlspeed\" interval=$INTERVAL N:$dlspeed"
echo "PUTVAL \"$HOSTNAME/exec-qbittorrent-speeds/gauge-upspeed\" interval=$INTERVAL N:$upspeed"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment