Skip to content

Instantly share code, notes, and snippets.

@salmonmoose
Created July 2, 2014 07:08
Show Gist options
  • Save salmonmoose/1c570d99bc6508e6fa73 to your computer and use it in GitHub Desktop.
Save salmonmoose/1c570d99bc6508e6fa73 to your computer and use it in GitHub Desktop.
Basic Collectd python plugin for Transmission
import collectd
import random
import transmissionrpc
pending = 0
checking = 0
downloading = 0
seeding = 0
stopped = 0
def read(data=None):
tc = transmissionrpc.Client('192.168.1.200', port=9091)
torrents = tc.get_torrents()
pending = 0
checking = 0
downloading = 0
queued = 0
seeding = 0
stopped = 0
rateDownload = 0
rateUpload = 0
for index in range(0, len(torrents)):
status = torrents[index].status
rateDownload += torrents[index].rateDownload
rateUpload += torrents[index].rateUpload
if status == 'check pending':
pending += 1
elif status == 'checking':
checking += 1
elif status == 'downloading':
downloading += 1
elif status == 'seeding':
seeding += 1
elif status == 'stopped':
stopped += 1
elif status == 'download pending':
queued += 1
v1 = collectd.Values(type='gauge')
v1.plugin = 'python.transmission.torrents.check_pending'
v1.dispatch(values=[pending])
v1.plugin = 'python.transmission.torrents.checking'
v1.dispatch(values=[checking])
v1.plugin = 'python.transmission.torrents.downloading'
v1.dispatch(values=[downloading])
v1.plugin = 'python.transmission.torrents.seeding'
v1.dispatch(values=[seeding])
v1.plugin = 'python.transmission.torrents.stopped'
v1.dispatch(values=[stopped])
v1.plugin = 'python.transmission.torrents.queued'
v1.dispatch(values=[queued])
v1.plugin = 'python.transmission.torrents.upload'
v1.dispatch(values=[rateUpload])
v1.plugin = 'python.transmission.torrents.download'
v1.dispatch(values=[rateDownload])
collectd.register_read(read)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment