Projet

Général

Profil

Révision 3a70dd84

ID3a70dd84b6a1e277233f733d489d6183ff776a76
Parent d89e5781
Enfant 289afa01

Ajouté par Rodolphe Qui?deville il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/geowebcache-cache-hits-ratio
1
#!/usr/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

  
11
geowebcache_volume - Plugin to monitor the cache hit ratio of GeoWebCache
12
servers.
13

  
14
version 1.0.1
15

  
16
=head1 CONFIGURATION
17

  
18
The following environment variables are used by this plugin
19

  
20
=over 4
21

  
22
=item timeout
23

  
24
Connection timeout
25

  
26
=item url
27

  
28
Override default status-url
29

  
30
=item ports
31

  
32
HTTP 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

  
44
Rodolphe Qui?deville <rodolphe@quiedeville.org>
45

  
46
=head1 USAGE
47

  
48
Needs access to
49
http://localhost:8080/gwc (or modify the address for another host).
50

  
51
If geowebcache is used inside GeoServer the url will be
52
http://localhost:8080/geoserver/gwc
53

  
54
GeoWebCache 1.2 or higher.
55

  
56
Tip: To see if it's already set up correctly, just run this plugin
57
with the parameter "autoconf". If you get a "yes", everything should
58
work like a charm already.
59

  
60
=head1 MAGIC MARKERS
61

  
62
 #%# family=contrib
63
 #%# capabilities=autoconf
64

  
65
=cut
66

  
67
use strict;
68

  
69
my $ret = undef;
70

  
71
if(!eval "require LWP::UserAgent;") {
72
    $ret = "LWP::UserAgent not found";
73
}
74

  
75
my $URL      = exists $ENV{'url'}      ? $ENV{'url'}      : "http://127.0.0.1:%d/geowebcache/home";
76
my $PORT     = exists $ENV{'ports'}    ? $ENV{'ports'}    : 8080;
77
my $TIMEOUT  = exists $ENV{'timeout'}  ? $ENV{'timeout'}  : 30;
78

  
79
my $url = sprintf $URL, $PORT;
80

  
81
if(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

  
97
if(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 geowebcache\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

  
111
my $ua = LWP::UserAgent->new(timeout => $TIMEOUT);
112
my $response = $ua->request(HTTP::Request->new('GET',$url));
113

  
114
if ($response->content =~ '<tr><td colspan="5"> </td></tr><tr><td colspan="2">Cache hit ratio:</td><td colspan="3">(\d\d?\.?\d+)% of requests</td></tr>' ) {
115
    print "ratio.value " . $1;
116
} else {
117
    print "ratio.value U\n";
118
}
119

  
120
# vim:syntax=perl

Formats disponibles : Unified diff