#!/usr/bin/perl # # Plugin to monitor the number of tomcat-threads running on the # machine, and (in addition to a simple process count), separate then # into "busy" or "idle" servers. # # Author: Rune Nordbøe Skillingstad # # Requirements: # - Needs access to http://:@localhost:8080/manager/status?XML=true (or modify the # address for another host). A munin-user in $CATALINA_HOME/conf/tomcat-users.xml # should be set up for this to work. # # Tip: To see if it's already set up correctly, just run this plugin # with the parameter "autoconf". If you get a "yes", everything should # work like a charm already. # # tomcat-users.xml example: # # # Parameters supported: # # config # autoconf # # Configurable variables # # timeout - Connection timeout # url - Override default status-url # ports - HTTP port numbers # user - Manager username # password - Manager password # # Magic markers: #%# family=auto #%# capabilities=autoconf use strict; my $ret = undef; if(!eval "require LWP::UserAgent;") { $ret = "LWP::UserAgent not found"; } if(!eval "require XML::Simple;") { $ret .= "XML::Simple not found"; } my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://%s:%s\@127.0.0.1:%d/manager/status?XML=true"; my $PORT = exists $ENV{'ports'} ? $ENV{'ports'} : 8080; my $USER = exists $ENV{'user'} ? $ENV{'user'} : "munin"; my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : "munin"; my $TIMEOUT = exists $ENV{'timeout'} ? $ENV{'timeout'} : 30; my $url = sprintf $URL, $USER, $PASSWORD, $PORT; if(exists $ARGV[0] and $ARGV[0] eq "autoconf") { if($ret) { print "no ($ret)\n"; exit 1; } my $au = LWP::UserAgent->new(timeout => $TIMEOUT); my $repsonse = $au->request(HTTP::Request->new('GET',$url)); if($repsonse->is_success and $repsonse->content =~ /.*<\/status>/im) { print "yes\n"; exit 0; } else { print "no (no tomcat status)\n"; exit 1; } } if(exists $ARGV[0] and $ARGV[0] eq "config") { print "graph_title Tomcat threads\n"; print "graph_args --base 1000 -l 0\n"; print "graph_vlabel threads\n"; print "graph_category tomcat\n"; print "graph_total total\n"; print "graph_order busy idle\n"; print "busy.label busy threads\n"; print "busy.draw AREA\n"; print "idle.label idle threads\n"; print "idle.draw STACK\n"; exit 0; } my $ua = LWP::UserAgent->new(timeout => $TIMEOUT); my $xs = new XML::Simple; my $response = $ua->request(HTTP::Request->new('GET',$url)); my $xml = $xs->XMLin($response->content); if($xml->{'connector'}->{'http-'.$PORT}->{'threadInfo'}->{'currentThreadsBusy'} && $xml->{'connector'}->{'http-'.$PORT}->{'threadInfo'}->{'currentThreadCount'}) { print "busy.value " . $xml->{'connector'}->{'http-'.$PORT}->{'threadInfo'}->{'currentThreadsBusy'} . "\n"; print "idle.value " . ($xml->{'connector'}->{'http-'.$PORT}->{'threadInfo'}->{'currentThreadCount'} - $xml->{'connector'}->{'http-'.$PORT}->{'threadInfo'}->{'currentThreadsBusy'}) . "\n"; } else { print "busy.value U\n"; print "idle.value U\n"; } # vim:syntax=perl