1#!/usr/local/bin/perl 2# -*- perl -*- 3 4# Author Rodolphe Quiédeville <rodolphe@quiedeville.org> 5# Licence : GPLv2 6# Code based on tomcat_volume plugin by 7# Rune Nordbøe Skillingstad <runesk@linpro.no> 8 9=head1 NAME 10 11geowebcache_volume - Plugin to monitor the cache hit ratio of GeoWebCache 12servers. 13 14version 1.0.1 15 16=head1 CONFIGURATION 17 18The following environment variables are used by this plugin 19 20=over 4 21 22=item timeout 23 24Connection timeout 25 26=item url 27 28Override default status-url 29 30=item ports 31 32HTTP port numbers 33 34=back 35 36=head2 CONFIGURATION EXAMPLE 37 38 [geowebcache_ratio] 39 env.url localhost:%d/geoserver/gwc 40 env.ports 8081 41 42=head1 AUTHOR 43 44Rodolphe Quiédeville <rodolphe@quiedeville.org> 45 46=head1 USAGE 47 48Needs access to 49http://localhost:8080/gwc (or modify the address for another host). 50 51If geowebcache is used inside GeoServer the url will be 52http://localhost:8080/geoserver/gwc 53 54GeoWebCache 1.2 or higher. 55 56Tip: To see if it's already set up correctly, just run this plugin 57with the parameter "autoconf". If you get a "yes", everything should 58work like a charm already. 59 60=head1 MAGIC MARKERS 61 62 #%# family=contrib 63 #%# capabilities=autoconf 64 65=cut 66 67use strict; 68 69my $ret = undef; 70 71if(!eval "require LWP::UserAgent;") { 72 $ret = "LWP::UserAgent not found"; 73} 74 75my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/geowebcache/home"; 76my $PORT = exists $ENV{'ports'} ? $ENV{'ports'} : 8080; 77my $TIMEOUT = exists $ENV{'timeout'} ? $ENV{'timeout'} : 30; 78 79my $url = sprintf $URL, $PORT; 80 81if(exists $ARGV[0] and $ARGV[0] eq "autoconf") { 82 if($ret) { 83 print "no ($ret)\n"; 84 exit 0; 85 } 86 my $au = LWP::UserAgent->new(timeout => $TIMEOUT); 87 my $response = $au->request(HTTP::Request->new('GET',$url)); 88 if($response->is_success and $response->content =~ /GWC Home/im) { 89 print "yes\n"; 90 exit 0; 91 } else { 92 print "no geowebcache found\n"; 93 exit 0; 94 } 95} 96 97if(exists $ARGV[0] and $ARGV[0] eq "config") { 98 print "graph_title GeoWebCache cache hit ratio\n"; 99 print "graph_args --base 1000\n"; 100 print "graph_vlabel %\n"; 101 print "graph_category loadbalancer\n"; 102 print "ratio.label percent\n"; 103 print "ratio.type GAUGE\n"; 104 print "ratio.max 100\n"; 105 print "ratio.min 0\n"; 106 print "ratio.draw AREA\n"; 107 print "ratio.colour FFCC00\n"; 108 exit 0; 109} 110 111my $ua = LWP::UserAgent->new(timeout => $TIMEOUT); 112my $response = $ua->request(HTTP::Request->new('GET',$url)); 113 114if ($response->content =~ '<tr><th colspan="2" scope="row">Cache hit ratio:</th><td colspan="3">(\d+\.\d+)% of requests</td></tr>' ) { 115 print "ratio.value " . $1 . "\n"; 116} else { 117 print "ratio.value U\n"; 118} 119 120# vim:syntax=perl 121