#!/usr/bin/perl -w ## ## Munin plugin for awstats ## Written by Espen Holm Nilsen (http://www.gho.no) ## ## Copyrighted under GPL or GPL2 ## ## (rename to "awstats_") ## To use this script, put it somewhere (for example /usr/share/munin/plugins/awstats_) ## Then symlink it to your munin plugins (ubuntu: ln -s /usr/share/munin/plugins/awstats_ /etc/munin/plugins/awstats_domain.tld ## The domain should match the one you use in your awstats url (awstats.pl?config=) use LWP; $0 =~ /awstats_(.+)*$/; my $name = $1; exit 2 unless defined $name; if(scalar(@ARGV) > 0 && $ARGV[0] eq 'config') { print "graph_title Traffic for " . $name . "\n"; print "graph_category Web\n"; print "graph_vlabel Traffic\n"; print "graph_scale no\n"; print "visits.label Visits\n"; print "hits.label Hits\n"; print "pages.label Pages\n"; print "visits.type COUNTER\n"; # can be commented out for wavy effect print "hits.type COUNTER\n"; # this one also print "pages.type COUNTER\n"; # this too! exit(0); } sub getTraffic { my ($domain) = @_; my $ua = LWP::UserAgent->new(); my $url = "http://example.net/awstats.pl?config=" . $domain . "&framename=mainright"; my $req = HTTP::Request->new('GET' => $url); my $res = $ua->request($req); my $content = $res->content; my @traffic; if ($content =~ /(\d{1,2}) ([A-Za-z]{1,4}) (\d{4})<\/font><\/td>(\d{1,9})<\/td>(\d{1,9})<\/td>(\d{1,9})<\/td>(.*)<\/td>/) { my $visits = $4; my $pages = $5; my $hits = $6; @traffic = ($visits, $pages, $hits); } return @traffic; } my @trafficStats = getTraffic($name); print "visits.value " . $trafficStats[0] . "\n"; print "pages.value " . $trafficStats[1] . "\n"; print "hits.value " . $trafficStats[2] . "\n";