Projet

Général

Profil

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

root / plugins / tomcat / tomcat_access @ 2cbf4a93

Historique | Voir | Annoter | Télécharger (3,01 ko)

1
#!/usr/bin/perl
2
# -*- perl -*-
3

    
4
=head1 NAME
5

    
6
tomcat_access - Plugin to monitor the number of accesses to Tomcat
7
servers.
8

    
9
=head1 CONFIGURATION
10

    
11
The following environment variables are used by this plugin
12

    
13
 timeout  - Connection timeout
14
 url      - Override default status-url
15
 ports    - HTTP port numbers
16
 user     - Manager username
17
 password - Manager password
18

    
19
=head1 USAGE
20

    
21
Requirements:
22

    
23
Needs access to
24
http://<user>:<password>@localhost:8080/manager/status?XML=true (or
25
modify the address for another host).
26

    
27
Tomcat 5.0 or higher.
28

    
29
A munin-user in $CATALINA_HOME/conf/tomcat-users.xml should be set up
30
for this to work.
31

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

    
36
tomcat-users.xml example:
37
 <user username="munin" password="<set this>" roles="standard,manager"/>
38

    
39
=head1 AUTHOR
40

    
41
Ricardo Fraile <rikr_@hotmail.com>
42
Rune Nordb?e Skillingstad <runesk@linpro.no>
43

    
44
=head1 LICENSE
45

    
46
GPL 2.
47

    
48
=head1 MAGIC MARKERS
49

    
50
 #%# family=manual
51
 #%# capabilities=autoconf
52

    
53
=cut
54

    
55
use strict;
56

    
57
my $ret = undef;
58

    
59
if(!eval "require LWP::UserAgent;") {
60
    $ret = "LWP::UserAgent not found";
61
}
62

    
63
if(!eval "require XML::Simple;") {
64
    $ret .= "XML::Simple not found";
65
} 
66

    
67
my $URL      = exists $ENV{'url'}      ? $ENV{'url'}      : "http://%s:%s\@127.0.0.1:%d/manager/status?XML=true";
68
my $PORT     = exists $ENV{'ports'}    ? $ENV{'ports'}    : 8080;
69
my $PNAME    = exists $ENV{'pname'}    ? $ENV{'pname'}    : "http-8080";
70
my $USER     = exists $ENV{'user'}     ? $ENV{'user'}     : "munin";
71
my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : "munin";
72
my $TIMEOUT  = exists $ENV{'timeout'}  ? $ENV{'timeout'}  : 30;
73

    
74
my $url = sprintf $URL, $USER, $PASSWORD, $PORT;
75

    
76
if(exists $ARGV[0] and $ARGV[0] eq "autoconf") {
77
    if($ret) {
78
	print "no ($ret)\n";
79
	exit 0;
80
    }
81
    my $au = LWP::UserAgent->new(timeout => $TIMEOUT);
82
    my $repsonse = $au->request(HTTP::Request->new('GET',$url));
83
    if($repsonse->is_success and $repsonse->content =~ /<status>.*<\/status>/im) {
84
	print "yes\n";
85
	exit 0;
86
    } else {
87
	print "no (no tomcat status)\n";
88
	exit 0;
89
    }
90
}
91

    
92
if(exists $ARGV[0] and $ARGV[0] eq "config") {
93
    print "graph_title Tomcat accesses\n";
94
    print "graph_args --base 1000\n";
95
    print "graph_vlabel accesses / \${graph_period}\n";
96
    print "graph_category tomcat\n";
97
    print "accesses.label Accesses\n";
98
    print "accesses.type DERIVE\n";
99
    print "accesses.max 1000000\n";
100
    print "accesses.min 0\n";
101
    exit 0;
102
}
103

    
104
my $ua = LWP::UserAgent->new(timeout => $TIMEOUT);
105
my $xs = new XML::Simple;
106
my $response = $ua->request(HTTP::Request->new('GET',$url));
107
my %options = ( KeyAttr => { connector => 'name' }, ForceArray => 1 );
108
my $xml = $xs->XMLin($response->content, %options);
109

    
110
if($xml->{'connector'}->{"\"".$PNAME."\""}->{'requestInfo'}->[0]->{'requestCount'}) {
111
    print "accesses.value " . $xml->{'connector'}->{"\"".$PNAME."\""}->{'requestInfo'}->[0]->{'requestCount'} . "\n";
112
} else {
113
    print "accesses.value U\n";
114
}
115

    
116
# vim:syntax=perl