Projet

Général

Profil

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

root / plugins / tomcat / tomcat_access @ 2c912170

Historique | Voir | Annoter | Télécharger (3,04 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
 pname	  - Nome of the connector
17
 user     - Manager username
18
 password - Manager password
19

    
20
=head1 USAGE
21

    
22
Requirements:
23

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

    
28
Tomcat 5.0 or higher.
29

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

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

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

    
40
=head1 AUTHOR
41

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

    
45
=head1 LICENSE
46

    
47
GPL 2.
48

    
49
=head1 MAGIC MARKERS
50

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

    
54
=cut
55

    
56
use strict;
57

    
58
my $ret = undef;
59

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

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

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

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

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

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

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

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

    
117
# vim:syntax=perl