summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-08-19 00:58:37 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-08-19 00:58:37 -0400
commitafe0a948a3d6e258957a3cbc8265735240933a19 (patch)
tree19a5347b3d345a980b63e5558904514f0a843d74
parent0b1e1740d3a0aeb5278bb15b0b71ac76e2de5d08 (diff)
improve
-rwxr-xr-xsystemd.py40
1 files 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__':