Projet

Général

Profil

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

root / plugins / other / apache_activity @ 1dcc690d

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

1
#!/usr/bin/perl
2
#
3
# Parameters supported:
4
#
5
# 	config
6
# 	autoconf
7
#
8
# Configurable variables
9
#
10
# 	url      - Override default status-url
11
#
12
# Magic markers:
13
#%# family=auto
14
#%# capabilities=autoconf
15

    
16
my $ret = undef;
17
if (!eval "require LWP::UserAgent;") {
18
    $ret = "LWP::UserAgent not found";
19
}
20

    
21
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/server-status?auto";
22
my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80);
23
my %chars = (
24
	     # '\_' => 'Waiting',
25
	     # 'S' => 'Starting up',
26
	     'R' => 'Reading request',
27
	     'W' => 'Sending reply',
28
	     'K' => 'Keepalive',
29
	     'D' => 'DNS lookup',
30
	     'C' => 'Closing',
31
	     # 'L' => 'Logging',
32
	     # 'G' => 'Gracefully finishing',
33
	     # 'I' => 'Idle cleanup',
34
	     # '\.' => 'Open slot',
35
	     );
36

    
37
#    "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
38
#    "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
39
#    "C" Closing connection, "L" Logging, "G" Gracefully finishing,
40
#    "I" Idle cleanup of worker, "." Open slot with no current process
41

    
42
if (exists $ARGV[0] and $ARGV[0] eq "autoconf") {
43
    if ($ret) {
44
	print "no ($ret)\n";
45
	exit 1;
46
    }
47
    my $ua = LWP::UserAgent->new(timeout => 30);
48
    my @badports;
49
    
50
    foreach my $port (@PORTS) {
51
	my $url = sprintf $URL, $port;
52
	my $response = $ua->request(HTTP::Request->new('GET',$url));
53
	push @badports, $port unless $response->is_success and $response->content =~ /Scoreboard/im;
54
    }
55
    
56
    if (@badports) {
57
	print "no (no apache server-status on ports @badports)\n";
58
	exit 1;
59
    } else {
60
	print "yes\n";
61
	exit 0;
62
    }
63
}
64

    
65
if (exists $ARGV[0] and $ARGV[0] eq "config") {
66
    print "graph_title Apache activity\n";
67
    print "graph_args --base 1000 -l 0\n";
68
    print "graph_category apache\n";
69
    print "graph_vlabel processes\n";
70
    foreach my $port (@PORTS) {
71
	while (my ($char, $val) = each (%chars)) {
72
	    $char =~ s/\\\./dot/;
73
            $char =~ s/\\\_/underline/;
74
            print "activity_${port}_${char}.label ";
75
	    print $val, "\n";
76
            print "activity_${port}_${char}.type GAUGE\n";
77
        }
78
    }    
79
    exit 0;
80
}
81

    
82
foreach my $port (@PORTS) {
83
    my $ua = LWP::UserAgent->new (timeout => 30);
84
    my $url = sprintf $URL, $port;
85
    my $response = $ua->request (HTTP::Request->new('GET',$url));
86
    if ($response->content =~ /^Scoreboard\:\s?(.*)$/sm) {
87
	my $string = $1;
88
	chomp $string;
89
	my @act = split (//, $string);
90
	foreach my $char (keys (%chars)) {
91
	    my $num = scalar (grep (/$char/, @act));
92
	    $char =~ s/\\\./dot/;
93
	    $char =~ s/\\\_/underline/;
94
	    print "activity_${port}_${char}.value $num\n";
95
	}
96
    }
97
}
98