Advertisement
josacar

Munin plugin for Cherokee web server

May 18th, 2011
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.67 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Munin Plugin for Cherokee in Python
  4. # Based on the work of Mateusz Pawlowski: http://www.mobygeek.net/projects/files/cherokee__type_.rb
  5. # Coded by the not-python-programmer Jose Luis Salas <<josacar at gmail dot com>>  ;)
  6.  
  7. #%# family=contrib
  8. # Cherokee has to have $host/about enabled with server info set to normal
  9. # Or you can change the variables below as you wish
  10. # Handling arguments
  11. #
  12. # cherokee_host_type_data Shows data transferred
  13. # cherokee_host_type_rate Shows data rate transfer
  14. # cherokee_host_type_mod Shows Modules
  15. # cherokee_host_type_conn Shows connections
  16.  
  17. # USAGE:
  18. # cp /home/user/cherokee__type_.py /usr/share/munin/plugins/cherokee__type_
  19. # chmod +x /usr/share/munin/plugins/cherokee__type_
  20. # ln -s /usr/share/munin/plugins/cherokee__type_ cherokee_host_type_data
  21. # ln -s /usr/share/munin/plugins/cherokee__type_ cherokee_localhost_type_data
  22. # ln -s /usr/share/munin/plugins/cherokee__type_ cherokee_localhost_type_conn
  23. # ln -s /usr/share/munin/plugins/cherokee__type_ cherokee_localhost_type_mod
  24. # ln -s /usr/share/munin/plugins/cherokee__type_ cherokee_localhost_type_rate
  25.  
  26.  
  27. import urllib
  28. import os
  29. import sys
  30. import re
  31.  
  32. about_location = "/about/info/py"
  33.  
  34. host = os.getenv('host');
  35. type = 'data';
  36.  
  37. host="localhost"
  38.  
  39. match = re.match('^(?:|.*\/)cherokee_([^_]+)_type_(.+)$', sys.argv[0])
  40. if match:
  41.     host=match.group(1)
  42.     type=match.group(2)
  43.     if re.match('^([^:]+):(\d+)$', host):
  44.         host=match.group(1)
  45.         type=match.group(2)
  46.  
  47. #print "HOST: " + host + " TYPE: " + type
  48.  
  49. def output_values(response):
  50.     if type == "mod" :
  51.         section = response["modules"]
  52.         for key in section:
  53.             print key + '.value ' + str(section[key])
  54.     elif type == "data" :
  55.         section = response["traffic"]
  56.         print "sent.value " + str(section["tx"])
  57.         print "received.value " + str(section["rx"])
  58.     elif type == "rate" :
  59.         section = response["traffic"]
  60.         print "sent.value " + str(section["tx"])
  61.         print "received.value " + str(section["rx"])
  62.     elif type == "conn" :
  63.         section = response["connections"]
  64.         for key in section:
  65.             print key + '.value ' + str(section[key])
  66.  
  67.  
  68. def get_data():
  69.     raw_data = urllib.urlopen( "http://%s%s" % (host,about_location)).read()
  70. #   print "DEBUG: " + raw_data
  71.     return eval(raw_data)
  72.  
  73. def munin_values(res):
  74.     output_values(res)
  75.  
  76. def munin_config(response):
  77.     print "graph_category cherokee"
  78.     if type == "rate":
  79.         print "graph_title Cherokee Data Transfer Rate"
  80.         print "graph_vlabel Bits sent(+) / received(-) per ${graph_period}"
  81.         print "graph_args --base 1000"
  82.         print "graph_info"
  83.         print "received.label Received"
  84.         print "received.graph no"
  85.         print "received.type COUNTER"
  86.         print "received.cdef received,8,*"
  87.         print "sent.label bps"
  88.         print "sent.type COUNTER"
  89.         print "sent.negative received"
  90.         print "sent.cdef sent,8,*"
  91.     elif type == "conn":
  92.         print "graph_title Cherokee Connections"
  93.         print "graph_vlabel Connections"
  94.         #print "graph_args --base 1000 --logarithmic"
  95.         print "graph_args --base 1000"
  96.         section = response["connections"]
  97.         for key in section:
  98.             print key.strip() + '.label ' + key.capitalize()
  99.             print key + '.draw AREASTACK'
  100.     elif type == "data":
  101.         print "graph_title Cherokee Data Transferred"
  102.         print "graph_vlabel Bytes"
  103.         print "sent.label Sent"
  104.         print "received.label Received"
  105.     elif type == "mod":
  106.         print "graph_title Cherokee Loaded Modules"
  107.         print "graph_vlabel Modules"
  108.         print "graph_args --base 1000 --lower-limit 0"
  109.         section = response["modules"]
  110.         for key in section:
  111.             print key + '.label ' + key.capitalize()
  112.             print key + '.draw AREASTACK'
  113.    
  114. if len(sys.argv) > 1 and sys.argv[1] == "config":
  115.     munin_config(get_data())
  116. else:
  117.     munin_values(get_data())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement