Graphes MRTG pour Apache

Rédigé par jdrien - - aucun commentaire

Script PERL apache2 :


#!/usr/bin/perl
# can return hits or bytes (counters)
@res = `GET http://localhost:80/server-status`;
foreach $res (@res) {
    if ($res =~ /Server uptime: (.*)$/) { $up = $1; last } else { next }
    if ($res =~ /Server at/) { $server = $res; last } else { next }
}

@res = `GET http://localhost:80/server-status?auto`;

foreach $res (@res) {
    if ($res =~ /Total Accesses: (\d+)/) { $d1 = $1; next }
    if ($res =~ /Total kBytes: (\d+)/) { $d2 = $1 * 1024; next }
}
$d1 = int($d1);
$d2 = int($d2);
if ($ARGV[0] eq "hits") {
    print "$d1\n";
    print "$d1\n";
} elsif ($ARGV[0] eq "bytes") {
    print "$d2\n";
    print "$d2\n";
}

print "$up\n";
$server = "mon_serveur";
print "$server\n";

que l'on lance par ./apache2 hits ou ./apache2 bytes

Partie du fichier de configuration MRTG :

## Apache2 hits ##
Target[apache2_hits]: `/etc/mrtg-sys/apache2 hits`
Colours[apache2_hits]: LIGHT BLUE#7AAFFF,BLUE#1000FF,DARK GREEN#006000,VIOLET#FF00FF
Options[apache2_hits]: perhour, nopercent, growright, noinfo, nobanner
PageTop[apache2_hits]: <h1>Hits Apache2</h1>
MaxBytes[apache2_hits]: 1000000
YLegend[apache2_hits]: hits/heure
ShortLegend[apache2_hits]: par heure   
LegendO[apache2_hits]: Hits:
Legend2[apache2_hits]: Hits horaires
Legend4[apache2_hits]: Hits Horaires max
Title[apache2_hits]: Hits horaires du serveur Apache
WithPeak[apache2_hits]: wmy

## Apache2 Traffic ##
Target[apache2_traffic]: `/etc/mrtg-sys/apache2 bytes`
Colours[apache2_traffic]: LIGHT BLUE#7AAFFF,BLUE#1000FF,DARK GREEN#006000,VIOLET#FF00FF
Options[apache2_traffic]: nopercent, growright, noinfo, nobanner
PageTop[apache2_traffic]: <h1>Traffic Apache</h1>
MaxBytes[apache2_traffic]:16000
AbsMax[apache2_traffic]:20000
YLegend[apache2_traffic]: octets/s
ShortLegend[apache2_traffic]: o/s
LegendO[apache2_traffic]: Traffic Apache:
Legend2[apache2_traffic]: Traffic Apache
Title[apache2_traffic]: Traffic du serveur Apache
WithPeak[apache2_traffic]: wmy
Legend4[apache2_traffic]: Traffic max Apache

Pour que cela fonctionne il faut bien sûr que le mod_status soit activé pour Apache.

Fil Rss des articles de ce mot clé