From afe0a948a3d6e258957a3cbc8265735240933a19 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 19 Aug 2017 00:58:37 -0400 Subject: improve --- systemd.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/systemd.py b/systemd.py index 9b85660..7024103 100755 --- a/systemd.py +++ b/systemd.py @@ -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__': -- cgit v1.2.3