mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
Added autoconf, configuration via ENV variables, magic markers.
This commit is contained in:
parent
0db07b5c4f
commit
e12b9690f4
1 changed files with 45 additions and 15 deletions
|
@ -6,14 +6,27 @@ Wildcard plugin to monitor Apache Tomcat connectors and/or JBoss' JVM.
|
||||||
To use this plugin:
|
To use this plugin:
|
||||||
1. Set site, username and password variables before you do anything else.
|
1. Set site, username and password variables before you do anything else.
|
||||||
2. Run plugin with suggest argument to get all the available options.
|
2. Run plugin with suggest argument to get all the available options.
|
||||||
3. Copy plugin to munin plugions folder and make it executable.
|
3. Copy plugin to munin plugins folder and make it executable.
|
||||||
3. Create symbolic links based on output from step 2. Examples:
|
4. Create symbolic links based on output from step 2. Examples:
|
||||||
tomcat_jvm - monitor JVM usage
|
tomcat_jvm - monitor JVM usage
|
||||||
tomcat_ajp-127.0.0.1-8009 - monitor ajp connector
|
tomcat_ajp-127.0.0.1-8009 - monitor ajp connector
|
||||||
tomcat_http-127.0.0.1-8080 - monitor http connector
|
tomcat_http-127.0.0.1-8080 - monitor http connector
|
||||||
4. Check links by running them.
|
5. Check links by running them.
|
||||||
5. Restart munin-node.
|
6. Restart munin-node.
|
||||||
6. Enjoy graphs.
|
7. Enjoy graphs.
|
||||||
|
|
||||||
|
Munin's muni-node-configure can be used to do steps 2, 3 and 4 for you.
|
||||||
|
|
||||||
|
Example of using munin-node configuration to configure the plugin:
|
||||||
|
|
||||||
|
[tomcat_jvm]
|
||||||
|
env.site http://127.0.0.1:8080/status?XML=true
|
||||||
|
env.username admin
|
||||||
|
env.password admin
|
||||||
|
|
||||||
|
Magic markers
|
||||||
|
#%# capabilities=autoconf suggest
|
||||||
|
#%# family=auto
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import urllib2
|
import urllib2
|
||||||
|
@ -26,6 +39,16 @@ site = 'http://127.0.0.1:8080/status?XML=true'
|
||||||
username = 'admin'
|
username = 'admin'
|
||||||
password = 'admin'
|
password = 'admin'
|
||||||
|
|
||||||
|
# Or do it with the environment variables in munin-node configuration.
|
||||||
|
if os.environ.has_key('site'):
|
||||||
|
site = os.environ['site']
|
||||||
|
|
||||||
|
if os.environ.has_key('username'):
|
||||||
|
username = os.environ['username']
|
||||||
|
|
||||||
|
if os.environ.has_key('password'):
|
||||||
|
password = os.environ['password']
|
||||||
|
|
||||||
# Timeout for urlopen.
|
# Timeout for urlopen.
|
||||||
required_version = (2, 6)
|
required_version = (2, 6)
|
||||||
current_version = sys.version_info[:2]
|
current_version = sys.version_info[:2]
|
||||||
|
@ -54,12 +77,11 @@ def site_auth():
|
||||||
request = urllib2.Request(url=site, headers={"Authorization": "Basic %s" % enc_string})
|
request = urllib2.Request(url=site, headers={"Authorization": "Basic %s" % enc_string})
|
||||||
try:
|
try:
|
||||||
if current_version >= required_version:
|
if current_version >= required_version:
|
||||||
return urllib2.urlopen(request, timeout=5).read()
|
return (0, urllib2.urlopen(request, timeout=5).read())
|
||||||
else:
|
else:
|
||||||
return urllib2.urlopen(request).read()
|
return (0, urllib2.urlopen(request).read())
|
||||||
except:
|
except:
|
||||||
print "Failed to access %s ... please check the configuration." % (site)
|
return (-1, "Failed to access %s" % site)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def jvm_data(data):
|
def jvm_data(data):
|
||||||
document = data.documentElement
|
document = data.documentElement
|
||||||
|
@ -117,16 +139,24 @@ def configure():
|
||||||
print "%s.info %s %s count" % (attr, ctx, attr)
|
print "%s.info %s %s count" % (attr, ctx, attr)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
data = xml.dom.minidom.parseString(site_auth())
|
status, data = site_auth()
|
||||||
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
||||||
configure()
|
configure()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if len(sys.argv) == 2 and sys.argv[1] == 'suggest':
|
elif len(sys.argv) == 2 and sys.argv[1] == 'suggest':
|
||||||
suggest(data)
|
suggest(xml.dom.minidom.parseString(data))
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
elif len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
||||||
|
if status == 0:
|
||||||
|
print "yes"
|
||||||
|
else:
|
||||||
|
print "no (%s)" % data
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if ctx == 'jvm':
|
|
||||||
jvm_data(data)
|
|
||||||
else:
|
else:
|
||||||
connector_data(data, ctx)
|
if ctx == 'jvm':
|
||||||
|
jvm_data(xml.dom.minidom.parseString(data))
|
||||||
|
else:
|
||||||
|
connector_data(xml.dom.minidom.parseString(data), ctx)
|
||||||
|
|
Loading…
Reference in a new issue