Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / geowebcache / geowebcache-blankitems @ 17f78427

Historique | Voir | Annoter | Télécharger (2,83 ko)

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_blankitems - Plugin to monitor the ratio of blank items served by
12
GeoWebCache 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_blankitems]
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=manual
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 Percent of blank requests\n";
99
    print "graph_args --base 1000\n";
100
    print "graph_vlabel %\n";
101
    print "graph_category loadbalancer\n";
102
    print "graph_info Blankidth graph is an average on the last 60 seconds\n";
103
    print "blank.draw LINE1\n";
104
    print "blank.label % of blank KML/HTML\n";
105
    print "blank.type GAUGE\n";
106
    print "blank.max 1000000000\n";
107
    print "blank.min 0\n";
108
    print "blank.colour 0068B3\n";
109
    exit 0;
110
}
111

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

    
115
if ($response->content =~ '<tr><td colspan="2">Blank/KML/HTML:</td><td colspan="3">(\d+\.?\d+)% of requests</td></tr>') {
116
    my $value = $1;
117
    $value = $value * 1024 if ($2 eq 'k');
118
    $value = $value * 1024 * 1024 if ($2 eq 'm');
119
    print "blank.value " . $value;
120
} else {
121
    print "blank.value U\n";
122
}
123

    
124
# vim:syntax=perl