diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-08-19 00:58:37 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-08-19 00:58:37 -0400 |
commit | afe0a948a3d6e258957a3cbc8265735240933a19 (patch) | |
tree | 19a5347b3d345a980b63e5558904514f0a843d74 | |
parent | 0b1e1740d3a0aeb5278bb15b0b71ac76e2de5d08 (diff) |
improve
-rwxr-xr-x | systemd.py | 40 |
1 files changed, 28 insertions, 12 deletions
@@ -14,24 +14,40 @@ def init(): def read(): global system_manager - dat = dict() + + dat = { + # These are the values of the + # basic/unit-name.h:UnitActiveStates enum. + 'NActiveUnits': 0, + 'NReloadingUnits': 0, + 'NInactiveUnits': 0, + 'NFailedUnits': 0, + 'NActivatingUnits': 0, + 'NDeactivatingUnits': 0 + } for unit in system_manager.ListUnits(): - key = ('count', 'N%sUnits' % unit[3].capitalize()) - dat[key] = dat.get(key, 0) + 1 + key = str('N%sUnits' % unit[3].capitalize()) + dat[key] = dat[key] + 1 - for count in ['NJobs']: - dat[('count', count)] = int(get_property(system_manager, count)) - for counter in ['NInstalledJobs', 'NFailedJobs']: - dat[('counter', counter)] = int(get_property(system_manager, counter)) + for prop in ['NJobs', 'NInstalledJobs', 'NFailedJobs']: + dat[prop] = int(get_property(system_manager, prop)) return dat def dump(dat): - for key, val in read().iteritems(): - if __name__ == '__main__': - print("%s => %s" % (key, val)) - else: - collectd.Values(plugin='systemd', type=key[0], type_instance=key[1], values=[val]).dispatch() + collectd.info("---- dump() ----") + for key, val in read().iteritems(): + if __name__ == '__main__': + print("%s => %s" % (key, val)) + else: + collectd.info("%s => %s" % (key, val)) + collectd.Values( + plugin='systemd', + type='count', + type_instance=key + ).dispatch( + values=[val] + ) if __name__ == '__main__': |