wiki:PluginPortrait/thttpd

thttpd is a super fast web server that we're using to serve static files. When you send thttpd a USR2 signal, it prints some info, including QPS, to syslog. On our machines that message ends up in /var/log/messages.

This plugin opens /var/log/messages and seeks to the end, then sends thttpd USR2, then looks for the message thttpd printed to /var/log/messages.

It needs to run as a user that has read privileges on /var/log/messages.

#!/usr/bin/perl

use strict;
use warnings;

if ($ARGV[0] && $ARGV[0] eq 'config') {
   print <<END;
graph_title thttpd QPS
graph_vlabel qps
qps.label qps
END

   exit;
}

use Fcntl ':seek';

my $pid = `cat /var/run/thttpd.pid` or die $!;
chomp $pid;

open(LOG, '/var/log/messages') or die $!;
seek(LOG, 0, SEEK_END) or die $!;

kill USR2 => $pid or die $!;
sleep 2;

seek(LOG, 0, 1) or die $!;

while (<LOG>) {
   next unless (/thttpd\[$pid\]:   thttpd/);
   my ($qps) = /([\d\.]+)\/sec/;

   if ($qps) {
      printf("qps.value %s\n", $qps);
      last;
   }
}
Last modified at 2006-09-24T08:15:52+02:00 Last modified on 2006-09-24T08:15:52+02:00