From 49c77b925af1c205747116a762000d99e192e2c8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 19 Aug 2017 21:00:14 -0400 Subject: Use custom collectd types for jobs and units --- systemd.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'systemd.py') diff --git a/systemd.py b/systemd.py index 1f28195..18cdb77 100755 --- a/systemd.py +++ b/systemd.py @@ -34,19 +34,20 @@ def read(): 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 + ('sd_units', 'active'): 0, + ('sd_units', 'reloading'): 0, + ('sd_units', 'inactive'): 0, + ('sd_units', 'failed'): 0, + ('sd_units', 'activating'): 0, + ('sd_units', 'deactivating'): 0, } for unit in system_manager.ListUnits(): - key = str('N%sUnits' % unit[3].capitalize()) + key = ('sd_units', str(unit[3])) dat[key] = dat[key] + 1 - for prop in ['NJobs', 'NInstalledJobs', 'NFailedJobs']: - dat[prop] = int(get_property(system_manager, prop)) + dat[('sd_jobs', 'queued')] = int(get_property(system_manager, 'NJobs')) + dat[('sd_jobs', 'installed')] = int(get_property(system_manager, 'NInstalledJobs')) + dat[('sd_jobs', 'failed')] = int(get_property(system_manager, 'NFailedJobs')) return dat @@ -62,8 +63,8 @@ else: for (key, val) in iteritems(read()): collectd.Values( plugin='systemd', - type='count', - type_instance=key + type=key[0], + type_instance=key[1] ).dispatch( values=[val] ) -- cgit v1.2.3