You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Doug Bloebaum <bl...@iii.co.uk> on 1998/09/25 13:16:02 UTC
hits/second strip chart
We humbly submit the following perl/Tk script which draws a strip
chart of apache's hits per second. Is there something better out
there that does a similar thing?
#!/usr/local/bin/perl -w
# Usage: hitmeter <server> <interval>
# using Tk, draw a simple strip chart showing an Apache httpd's
# hits/second over a given interval and a high water mark over the
# life of the chart. Requires mod_status.o, and makes gross
# assumptions about the format of its output.
use strict;
use Tk;
use LWP::Simple;
my $usage = "Usage: $0 <server> [<interval>]\n";
my $server = shift or die $usage;
# Things you might want to change...
my $width = 200; # width of chart in pixels
my $height = 100; # height of chart in pixels
my $scale = 1; # multiplier for line height
my $interval = shift; # seconds between checks
$interval = 1 unless defined $interval;
my $serverStatusUrl = "http://$server/server-status?auto";
# Things you can ignore...
my $lastSec = 0;
my $lastAcc = 0;
$SIG{ALRM} = \&catch_alarm;
my $mw = MainWindow->new;
my $c = $mw->Canvas(-width => $width,
-height => $height,
-bg => 'white');
my $t = $c->createText(5,5,
-anchor => 'nw',
-text => "Starting ...");
$c->pack;
alarm 1;
MainLoop;
my (%l, $i, $high, $ave, $res, $sec, $acc, $secDelta, $accDelta);
my $highWaterMark = $c->createLine(0,0,0,0);
sub catch_alarm {
$_ = LWP::Simple::get($serverStatusUrl);
($sec) = /Uptime: ([0-9]+)/;
($acc) = /Total Accesses: ([0-9]+)/;
unless (defined($sec) && defined($acc)) {
warn "$0: Couldn't find my data from $serverStatusUrl\n";
die "$0: Here's what $serverStatusUrl returned: \n$_\n";
}
$secDelta = $sec - $lastSec;
$accDelta = $acc - $lastAcc;
$ave = int(($accDelta / $secDelta) + 0.5);
$high = 0 unless defined $high;
$high = $ave if $high < $ave;
$c->delete($l{0});
$c->delete($highWaterMark);
for ($i=0;$i<$width;$i++) {
$l{$i}=$l{$i+1};
$c->move($l{$i},-1,0);
}
$l{$width} = $c->createLine($width,$height,
$width,$height-$scale*$ave);
$c->itemconfigure($t,
-text => "hits/sec: " . $ave . " high: " . $high);
$highWaterMark = $c->createLine(0,$height-$scale*$high,
$width,$height-$scale*$high,
-fill => 'blue');
$c->update;
$lastSec = $sec;
$lastAcc = $acc;
alarm $interval;
}