sysctl.py.j2 588 B

1234567891011121314151617181920212223
  1. #!/usr/bin/python
  2. import subprocess, collectd
  3. def getStats(entries):
  4. sysctl = ['sysctl', '-n']
  5. return dict(zip(entries, subprocess.check_output(sysctl + entries).split('\n')))
  6. def read(data=None):
  7. stats = getStats(['net.netfilter.nf_conntrack_max', 'net.netfilter.nf_conntrack_count'])
  8. for k,v in stats.iteritems():
  9. vl = collectd.Values(type='gauge')
  10. vl.plugin='sysctl'
  11. vl.type_instance = k
  12. vl.dispatch(values=[v])
  13. def write(vl, data=None):
  14. for i in vl.values:
  15. print "%s (%s): %f" % (vl.plugin, vl.type, i)
  16. collectd.register_read(read)
  17. collectd.register_write(write)