bundlewrap/bundles/transmission/files/telegraf-transmission-plugin
Franziska Kunsmann df192e543b
Some checks failed
bundlewrap/pipeline/head There was a failure building this commit
bundles/transmission: add telegraf statistics
2021-05-19 20:12:52 +02:00

34 lines
1.4 KiB
Python

#!/usr/bin/env python3
from transmission_rpc import Client
c = Client(host='127.0.0.1', port=${rpc_port})
torrents = c.get_torrents()
total_progress = 0
total_available = 0
total_upload = 0
total_download = 0
for torrent in torrents:
name = torrent.name.replace(' ', '\\ ')
print(f'transmission,type=detail,name={name} percent_done={torrent.progress}')
print(f'transmission,type=detail,name={name} percent_avail={torrent.available}')
print(f'transmission,type=detail,name={name} ratio={torrent.ratio}')
print(f'transmission,type=detail,name={name} size={torrent.total_size}')
print(f'transmission,type=detail,name={name} upload={torrent.rateUpload}')
print(f'transmission,type=detail,name={name} download={torrent.rateDownload}')
total_progress += torrent.progress
total_available += torrent.available
total_upload += torrent.rateUpload
total_download += torrent.rateDownload
total_progress_pct = round((total_progress/(len(torrents)*100))*100, 3)
total_available_pct = round((total_available/(len(torrents)*100))*100, 3)
print(f'transmission,type=global num_torrents={len(torrents)}')
print(f'transmission,type=global percent_done={total_progress_pct}')
print(f'transmission,type=global percent_avail={total_available_pct}')
print(f'transmission,type=global upload={total_upload}')
print(f'transmission,type=global download={total_download}')