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 --- read-systemd.conf | 2 ++ systemd.py | 23 ++++++++++++----------- systemd.types.db | 2 ++ 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 systemd.types.db diff --git a/read-systemd.conf b/read-systemd.conf index 51befb5..f3870b6 100644 --- a/read-systemd.conf +++ b/read-systemd.conf @@ -1,3 +1,5 @@ +TypesDB "/home/luke/src/collectd-systemd/systemd.types.db" + LoadPlugin python ModulePath "/home/luke/src/collectd-systemd" 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] ) diff --git a/systemd.types.db b/systemd.types.db new file mode 100644 index 0000000..bf45e3a --- /dev/null +++ b/systemd.types.db @@ -0,0 +1,2 @@ +sd_units value:GAUGE:0:U +sd_jobs value:GAUGE:0:U -- cgit v1.2.3