mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
133 lines
4.0 KiB
Plaintext
133 lines
4.0 KiB
Plaintext
|
#!/usr/bin/python
|
||
|
|
||
|
'''
|
||
|
Wildcard plugin to monitor Apache Tomcat connectors and/or JBoss' JVM.
|
||
|
|
||
|
To use this plugin:
|
||
|
1. Set site, username and password variables before you do anything else.
|
||
|
2. Run plugin with suggest argument to get all the available options.
|
||
|
3. Copy plugin to munin plugions folder and make it executable.
|
||
|
3. Create symbolic links based on output from step 2. Examples:
|
||
|
tomcat_jvm - monitor JVM usage
|
||
|
tomcat_ajp-127.0.0.1-8009 - monitor ajp connector
|
||
|
tomcat_http-127.0.0.1-8080 - monitor http connector
|
||
|
4. Check links by running them.
|
||
|
5. Restart munin-node.
|
||
|
6. Enjoy graphs.
|
||
|
'''
|
||
|
|
||
|
import urllib2
|
||
|
import base64
|
||
|
import xml.dom.minidom
|
||
|
import sys, os, re
|
||
|
|
||
|
# Configure me ...
|
||
|
site = 'http://127.0.0.1:8080/status?XML=true'
|
||
|
username = 'admin'
|
||
|
password = 'admin'
|
||
|
|
||
|
# Timeout for urlopen.
|
||
|
required_version = (2, 6)
|
||
|
current_version = sys.version_info[:2]
|
||
|
|
||
|
connector_attrs = (
|
||
|
'maxThreads',
|
||
|
'minSpareThreads',
|
||
|
'maxSpareThreads',
|
||
|
'currentThreadCount',
|
||
|
'currentThreadBusy'
|
||
|
)
|
||
|
|
||
|
jvm_attrs = (
|
||
|
'free',
|
||
|
'total',
|
||
|
'max'
|
||
|
)
|
||
|
|
||
|
ctx = sys.argv[0].rstrip('.py').split('_')[1]
|
||
|
|
||
|
def site_auth():
|
||
|
# Prepare base64 encoded string
|
||
|
enc_string = base64.encodestring('%s:%s' % (username, password))
|
||
|
|
||
|
# Prepare request and add headers
|
||
|
request = urllib2.Request(url=site, headers={"Authorization": "Basic %s" % enc_string})
|
||
|
try:
|
||
|
if current_version >= required_version:
|
||
|
return urllib2.urlopen(request, timeout=5).read()
|
||
|
else:
|
||
|
return urllib2.urlopen(request).read()
|
||
|
except:
|
||
|
print "Failed to access %s ... please check the configuration." % (site)
|
||
|
sys.exit(1)
|
||
|
|
||
|
def jvm_data(data):
|
||
|
document = data.documentElement
|
||
|
for sub_document in document.childNodes:
|
||
|
if sub_document.nodeName == 'jvm':
|
||
|
node = sub_document.firstChild
|
||
|
for attr in jvm_attrs:
|
||
|
print "%s.value %s" % (attr, int(node.getAttribute(attr)))
|
||
|
|
||
|
def connector_data(data, connector_name):
|
||
|
document = data.documentElement
|
||
|
for sub_document in document.childNodes:
|
||
|
if sub_document.nodeName == 'connector' and sub_document.getAttribute('name') == connector_name:
|
||
|
node = sub_document.firstChild
|
||
|
for attr in connector_attrs:
|
||
|
try:
|
||
|
print "%s.value %s" % (attr, int(node.getAttribute(attr)))
|
||
|
except:
|
||
|
pass
|
||
|
|
||
|
def suggest(data):
|
||
|
document = data.documentElement
|
||
|
for sub_document in document.childNodes:
|
||
|
if sub_document.nodeName == 'jvm':
|
||
|
print "jvm"
|
||
|
elif sub_document.nodeName == 'connector':
|
||
|
print sub_document.getAttribute('name')
|
||
|
else:
|
||
|
pass
|
||
|
|
||
|
def configure():
|
||
|
print "graph_title Tomcat status - %s" % ctx
|
||
|
print "graph_category tomcat"
|
||
|
if ctx == 'jvm':
|
||
|
print "graph_args --base 1024 -l 0"
|
||
|
print "graph_scale yes"
|
||
|
print "graph_vlabel JVM in bytes"
|
||
|
print "graph_info This graph shows JVM usage of Tomcat."
|
||
|
for attr in jvm_attrs:
|
||
|
print "%s.label %s" % (attr, attr)
|
||
|
print "%s.type GAUGE" % (attr)
|
||
|
print "%s.min 0" % (attr)
|
||
|
print "%s.draw LINE1" % (attr)
|
||
|
print "%s.info %s %s in bytes" % (attr, ctx, attr)
|
||
|
else:
|
||
|
print "graph_args --base 1000 -l 0"
|
||
|
print "graph_scale no"
|
||
|
print "graph_vlabel Connector threads"
|
||
|
print "graph_info This graph shows connector threads for %s" % ctx
|
||
|
for attr in connector_attrs:
|
||
|
print "%s.label %s" % (attr, attr)
|
||
|
print "%s.type GAUGE" % (attr)
|
||
|
print "%s.min 0" % (attr)
|
||
|
print "%s.draw LINE1" % (attr)
|
||
|
print "%s.info %s %s count" % (attr, ctx, attr)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
data = xml.dom.minidom.parseString(site_auth())
|
||
|
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
||
|
configure()
|
||
|
sys.exit(0)
|
||
|
|
||
|
if len(sys.argv) == 2 and sys.argv[1] == 'suggest':
|
||
|
suggest(data)
|
||
|
sys.exit(0)
|
||
|
|
||
|
if ctx == 'jvm':
|
||
|
jvm_data(data)
|
||
|
else:
|
||
|
connector_data(data, ctx)
|