bundles/transmission: add telegraf statistics
Some checks failed
bundlewrap/pipeline/head There was a failure building this commit

This commit is contained in:
Franzi 2021-05-19 20:12:52 +02:00
parent 3b3bdeecab
commit df192e543b
Signed by: kunsi
GPG key ID: 12E3D2136B818350
4 changed files with 65 additions and 2 deletions

View file

@ -59,13 +59,13 @@ telegraf_config = {
# is a dict, of which we only use the value of it. This also allows us
# to overwrite values set by metadata defaults/reactors in node and group
# metadata, if needed.
for config in node.metadata.get('telegraf/input_plugins/exec', {}).values():
for config in sorted(node.metadata.get('telegraf/input_plugins/exec', {}).values(), key=lambda c: ''.join(c['commands'])):
if 'exec' not in telegraf_config['inputs']:
telegraf_config['inputs']['exec'] = []
telegraf_config['inputs']['exec'].append(config)
for config in node.metadata.get('telegraf/input_plugins/execd', {}).values():
for config in sorted(node.metadata.get('telegraf/input_plugins/execd', {}).values(), key=lambda c: ''.join(c['commands'])):
if 'execd' not in telegraf_config['inputs']:
telegraf_config['inputs']['execd'] = []

View file

@ -0,0 +1,34 @@
#!/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}')

View file

@ -1,5 +1,13 @@
from bundlewrap.metadata import metadata_to_json
pkg_pip = {
'transmission-rpc': {
'needed_by': {
'svc_systemd:telegraf',
},
},
}
files = {
# XXX Manage settings using bundlewrap once transmission has an
# option to disable config rewriting.
@ -14,6 +22,13 @@ files = {
'svc_systemd:transmission-daemon:restart',
},
},
'/usr/local/bin/telegraf-transmission-plugin': {
'content_type': 'mako',
'context': {
'rpc_port': node.metadata['transmission']['config']['rpc-port'],
},
'mode': '0755',
},
}
actions = {

View file

@ -34,6 +34,20 @@ defaults = {
},
}
if node.has_bundle('telegraf'):
defaults['telegraf'] = {
'input_plugins': {
'exec': {
'transmission': {
'commands': ['telegraf-transmission-plugin'],
'interval': '10s',
'data_format': 'influx',
'timeout': '5s',
},
},
},
}
@metadata_reactor.provides(
'iptables/port_rules',