l2tp.py.j2 736 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/python
  2. import collectd
  3. from pybrctl import BridgeController
  4. def getBridgeInterfaceCount():
  5. ifcount = {}
  6. brctl = BridgeController()
  7. for br in brctl.showall():
  8. ifcount[br.name] = len(br.getifs())
  9. return ifcount
  10. def read(data=None):
  11. stats = getBridgeInterfaceCount()
  12. globalCount = 0
  13. for k,v in stats.iteritems():
  14. globalCount += v
  15. vl = collectd.Values(type='if_count')
  16. vl.plugin='l2tp'
  17. vl.type_instance = k
  18. vl.dispatch(values=[v])
  19. vl = collectd.Values(type='if_count')
  20. vl.plugin='l2tp'
  21. vl.type_instance = 'all'
  22. vl.dispatch(values=[globalCount])
  23. def write(vl, data=None):
  24. for i in vl.values:
  25. print "%s (%s): %f" % (vl.plugin, vl.type, i)
  26. collectd.register_read(read)
  27. collectd.register_write(write);