1#!/bin/sh
2#
3# Wildcard-plugin to monitor Java JMX (http://java.sun.com/jmx)attributes.
4# To monitor a # specific set of JMX attributes,
5# link <config_name> to this file. E.g.
6#
7#    ln -s /usr/share/plugins/jmx_ /etc/munin/plugins/jmx_java_threads
8#
9
10# ...will monitor Java thread count, assuming java_threads.conf file is located in
11# /etc/munin/plugins folder.
12#
13# For Java process to be monitored, it must expose JMX remote interface.
14# With Java 1.5 it can be done by adding parameters as:
15#
16# -Dcom.sun.management.jmxremote.port=<PORT> -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
17#
18# For Tomcat to be monitored, add the following line in catalina.bat script:
19# set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=<PORT> -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
20#
21# By default, the plugin monitors localhost on <PORT> = 1616 using URL
22# service:jmx:rmi:///jndi/rmi://localhost:1616/jmxrmi
23# It can be changed by specifying parameters in  /etc/munin/plugin-conf.d/munin-node
24#
25# [jmx_*]
26# env.jmxurl service:jmx:rmi:///jndi/rmi://localhost:1616/jmxrmi
27#
28# Read more on JMX configuring at http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html
29# $Log$
30#
31LINK=`readlink $0`
32CONFIGNAME=`basename $0 | sed 's/^jmx_//g'`.conf
33RDIR=`dirname $LINK`
34
35if [ "$jmxurl" = "" ]; then
36SERVICE=service:jmx:rmi:///jndi/rmi://localhost:1616/jmxrmi
37else
38SERVICE="$jmxurl"
39fi
40
41if [ "$jmxuser" != "" ]; then
42CREDS="--user=$jmxuser --pass=$jmxpass"
43fi
44
45# checks
46test -z $CONFIGNAME || test -z "$RDIR" && exit 1
47
48JMXQUERY="java -cp $RDIR/jmxquery.jar org.munin.JMXQuery --url=$SERVICE $CREDS --conf=$RDIR/$CONFIGNAME"
49
50
51case $1 in
52        (config)        $JMXQUERY config;;
53        (*)             $JMXQUERY       ;;
54esac
55