root / plugins / apache / apache_watch_ @ e5ce7492
Historique | Voir | Annoter | Télécharger (3,32 ko)
| 1 | 8b6dfd0b | Bj?rn Ruberg | #!/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 | # Must be symlinked to what the graph should monitor. Run with --suggest |
||
| 13 | # to see valid targets - or just run munin-node-configure --shell |
||
| 14 | # |
||
| 15 | # Written by Bj?rn Ruberg 2006-2007 |
||
| 16 | # |
||
| 17 | # Magic markers: |
||
| 18 | #%# family=auto |
||
| 19 | #%# capabilities=autoconf suggest |
||
| 20 | |||
| 21 | my $ret = undef; |
||
| 22 | if (!eval "require LWP::UserAgent;") {
|
||
| 23 | $ret = "LWP::UserAgent not found"; |
||
| 24 | } |
||
| 25 | |||
| 26 | # watch-list exists on localhost |
||
| 27 | # watch-info does not |
||
| 28 | |||
| 29 | my %plugs = ( |
||
| 30 | 'bytes' => 'Input/output (bytes)', |
||
| 31 | 'requests' => 'Requests', |
||
| 32 | 'documents' => 'Documents served', |
||
| 33 | ); |
||
| 34 | |||
| 35 | my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://localhost:%d/watch-list";
|
||
| 36 | my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80);
|
||
| 37 | my $type = "throughput"; |
||
| 38 | |||
| 39 | if (exists $ARGV[0] and $ARGV[0] eq "autoconf") {
|
||
| 40 | if ($ret) {
|
||
| 41 | print "no ($ret)\n"; |
||
| 42 | exit 1; |
||
| 43 | } |
||
| 44 | my $ua = LWP::UserAgent->new (timeout => 30); |
||
| 45 | my @badports; |
||
| 46 | |||
| 47 | foreach my $port (@PORTS) {
|
||
| 48 | my $url = sprintf $URL, $port; |
||
| 49 | my $response = $ua->request (HTTP::Request->new('GET', $url));
|
||
| 50 | push @badports, $port unless $response->is_success; |
||
| 51 | } |
||
| 52 | |||
| 53 | if (@badports) {
|
||
| 54 | print "no (no mod_watch exists on ports @badports)\n"; |
||
| 55 | exit 1; |
||
| 56 | } else {
|
||
| 57 | print "yes\n"; |
||
| 58 | exit 0; |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | if (exists $ARGV[0] and $ARGV[0] eq "suggest") {
|
||
| 63 | while (my ($key, undef) = each %plugs) {
|
||
| 64 | print "$key\n"; |
||
| 65 | } |
||
| 66 | exit 0; |
||
| 67 | } |
||
| 68 | |||
| 69 | my @servers = (); |
||
| 70 | my @data; |
||
| 71 | foreach my $port (@PORTS) {
|
||
| 72 | my $ua = LWP::UserAgent->new (timeout => 30); |
||
| 73 | my $url = sprintf $URL, $port; |
||
| 74 | my $response = $ua->request (HTTP::Request->new ('GET', $url));
|
||
| 75 | foreach my $string (split (/\n/, $response->content)) {
|
||
| 76 | my ($server, undef, $ifInOctets, $ifOutOctets, $ifRequests, |
||
| 77 | $ifDocuments) = split (/\s/, $string, 6); |
||
| 78 | push @servers, $server unless $server eq "SERVER"; |
||
| 79 | push @data, "$server $ifInOctets $ifOutOctets $ifRequests $ifDocuments" |
||
| 80 | unless $server eq "SERVER"; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | # From here and out, the plugin must be run with a symlinked service. |
||
| 85 | my $check = join ("|", keys %plugs);
|
||
| 86 | die ("Plugin must be symlinked to aspect to be monitored")
|
||
| 87 | unless $0 =~ /\_($check)$/; |
||
| 88 | |||
| 89 | my $action = $1; |
||
| 90 | |||
| 91 | if (exists $ARGV[0] and $ARGV[0] eq "config") {
|
||
| 92 | print "graph_title Apache $plugs{$action}\n";
|
||
| 93 | print "graph_args --base 1000 -l 0\n"; |
||
| 94 | print "graph_category apache\n"; |
||
| 95 | print "graph_vlabel activity\n"; |
||
| 96 | my $i = 0; |
||
| 97 | foreach my $server (sort (@servers)) {
|
||
| 98 | (my $txtserver = $server) =~ s/(-|\.)/\_/g; |
||
| 99 | my $draw = ($i==0) ? 'AREA' : 'STACK'; |
||
| 100 | if ($action eq "bytes") {
|
||
| 101 | print "${txtserver}.label $server\n";
|
||
| 102 | print "${txtserver}.draw $draw\n";
|
||
| 103 | print "${txtserver}.type COUNTER\n";
|
||
| 104 | } else {
|
||
| 105 | print "${txtserver}.label $server\n";
|
||
| 106 | print "${txtserver}.draw $draw\n";
|
||
| 107 | print "${txtserver}.type COUNTER\n";
|
||
| 108 | } |
||
| 109 | $i++; |
||
| 110 | } |
||
| 111 | exit 0; |
||
| 112 | } |
||
| 113 | |||
| 114 | foreach my $string (sort (@data)) {
|
||
| 115 | my ($server, $ifInOctets, $ifOutOctets, $ifRequests, $ifDocuments) = |
||
| 116 | split (/\s/, $string); |
||
| 117 | (my $txtserver = $server) =~ s/(-|\.)/\_/g; |
||
| 118 | if ($action eq "documents") {
|
||
| 119 | print "${txtserver}.value $ifDocuments\n";
|
||
| 120 | } elsif ($action eq "requests") {
|
||
| 121 | print "${txtserver}.value $ifRequests\n";
|
||
| 122 | } elsif ($action eq "bytes") {
|
||
| 123 | print "${txtserver}.value " . ($ifInOctets + $ifOutOctets) . "\n";
|
||
| 124 | } |
||
| 125 | } |
