#!/usr/bin/perl =head1 NAME tomcat_volume - Plugin to monitor the volume of data sent from Tomcat servers. =head1 CONFIGURATION The following environment variables are used by this plugin =over 4 =item url Override default status-url =item port HTTP port number =item user Manager username =item password Manager password =back =head2 CONFIGURATION EXAMPLE [tomcat_volume] env.ports 8081 env.user someuser env.password somepassword env.connector http-8081 =head1 AUTHOR Rune Nordbøe Skillingstad =head1 USAGE Needs access to http://:@localhost:8080/manager/status?XML=true (or modify the address for another host). Tomcat 5.0 or higher. 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: =head1 MAGIC MARKERS #%# family=manual #%# capabilities=autoconf =cut use strict; use warnings; use Munin::Plugin::HTTP; use URI::Escape; my $ret = undef; if(!eval "require XML::Simple;") { $ret .= "XML::Simple not found"; } my $UA = Munin::Plugin::HTTP->new; my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://%s:%s\@%s:%d/manager/status?XML=true"; my $PORT = exists $ENV{'port'} ? $ENV{'port'} : exists $ENV{'ports'} ? $ENV{'ports'} : 8080; my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1"; 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 $CONNECTOR= $ENV{'connector'}; my $url = sprintf $URL, uri_escape($USER), uri_escape($PASSWORD), $HOST, $PORT; if(exists $ARGV[0] and $ARGV[0] eq "autoconf") { if($ret) { print "no ($ret)\n"; exit 0; } my $response = $UA->get($url); if($response->is_success and $response->content =~ /.*<\/status>/im) { print "yes\n"; exit 0; } else { print "no (no tomcat status)\n"; exit 0; } } my $xs = new XML::Simple; my $response = $UA->get($url); my %options = ( KeyAttr => { connector => 'name' }, ForceArray => 1 ); my $xml = $xs->XMLin($response->content, %options); my @connectors; if(defined $CONNECTOR) { push @connectors, $CONNECTOR; } else { @connectors = keys %{$xml->{'connector'}}; } if(exists $ARGV[0] and $ARGV[0] eq "config") { print "graph_title Tomcat volume\n"; print "graph_args --base 1000\n"; print "graph_vlabel bytes per \${graph_period}\n"; print "graph_category appserver\n"; for my $connector (@connectors) { my $clean = clean_fieldname($connector); print "${clean}_volume.label $connector bytes\n"; print "${clean}_volume.type DERIVE\n"; print "${clean}_volume.max 1000000000\n"; print "${clean}_volume.min 0\n"; } } else { for my $connector (@connectors) { my $clean = clean_fieldname($connector); if(exists $xml->{'connector'}->{$connector}->{'requestInfo'}->[0]->{'bytesSent'}) { print "${clean}_volume.value " . $xml->{'connector'}->{$connector}->{'requestInfo'}->[0]->{'bytesSent'} . "\n"; } else { print "${clean}_volume.value U\n"; } } }