#! /usr/bin/perl # anders@aftenposten.no, 2007-04-11 # Show the service time for Squid #use Sys::Hostname; #use Time::HiRes qw( time ); #use IO::Socket; use Net::SNMP; # ----- config ----- $oid=".1.3.6.1.4.1.3495.1.3.2.2.1.2.5"; $host="localhost"; $community="foobar"; $port=3401; # ----- config ----- sub snmpgetvalue { my $response = $session->get_request($oid); if (!defined($response->{$oid})) { return undef; } else { return $response->{$oid}; } } sub printvalues { my $label = shift; my ($session, $error) = Net::SNMP->session( -hostname => $host, -community => $community, -port => $port ); if (defined ($session)) { my $response = $session->get_request($oid); if (!defined($response->{$oid})) { print "$label.value 0\n"; } else { my $value=$response->{$oid}; print "$label.value $value\n"; } } else { die("Can not connect to SNMP agent on $host:$port"); } } if ($ARGV[0] && $ARGV[0] eq "autoconf") { print "yes\n"; } elsif ($ARGV[0] && $ARGV[0] eq "config") { print "graph_title Service time\n"; print "graph_vlabel ms\n"; print "graph_category squid\n"; print "graph_info This graph shows the service time for Squid to handle a request\n"; print "graph_order svctime\n"; print "graph_scale yes\n"; print "svctime.label hits\n"; print "svctime.type GAUGE\n"; print "svctime.graph yes\n"; } else { printvalues("svctime"); }