Projet

Général

Profil

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

root / plugins / other / geowebcache-bandwidth @ 289afa01

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

1 289afa01 Rodolphe Qui?deville
#!/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_bandwidth - Plugin to monitor the bandwidth 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_bandwidth]
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 http://localhost:8080/gwc (or
49
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 bandwidth\n";
99
    print "graph_args --base 1024\n";
100
    print "graph_vlabel bit/s\n";
101
    print "graph_category geowebcache\n";
102
    print "graph_info Bandwidth graph is an average on the last 60 seconds\n";
103
    print "bandw.draw LINE1\n";
104
    print "bandw.label bandwidth bit/s\n";
105
    print "bandw.type GAUGE\n";
106
    print "bandw.max 1000000000\n";
107
    print "bandw.min 0\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>60 seconds</td><td>\d+</td><td>\d+.\d+ /s</td><td>\d+</td><td>(\d+\.\d+) ([km]?)bps') {
115
    my $value = $1;
116
    $value = $value * 1024 if ($2 eq 'k');
117
    $value = $value * 1024 * 1024 if ($2 eq 'm');
118
    print "bandw.value " . $value;
119
} else {
120
    print "bandw.value U\n";
121
}
122
123
# vim:syntax=perl