s4ros

Apache collector

Sep 26th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import diamond.collector
  2. import urllib
  3.  
  4. TO_PUBLISH = ['TotalAccesses', 'TotalkBytes', 'BusyWorkers', 'IdleWorkers']
  5.  
  6. class ApacheCollector(diamond.collector.Collector):
  7.  
  8.     def get_default_config(self):
  9.         config = super(ApacheCollector, self).get_default_config()
  10.         config.update({
  11.             'URL': 'http://localhost/server-status'
  12.         })
  13.         return config
  14.  
  15.     def collect(self):
  16.         content = urllib.urlopen(self.config['URL'] + '?auto')
  17.         for line in content:
  18.             line.rstrip()
  19.             line = line.replace(' ', '')
  20.             key, value = line.split(':')
  21.             if key in TO_PUBLISH:
  22.                 self.publish(key, value)
  23.         return None
Add Comment
Please, Sign In to add comment