diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2010-02-18 13:24:00 +0000 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2010-02-18 13:24:00 +0000 |
commit | 9d9811481c452a891ebecb6f666064ed323107d1 (patch) | |
tree | f4552c1c5609427413dae6a810d739fdcf4c582a | |
parent | f1cdc0cb061bef68d1a59551e83ceb0d4c28356e (diff) |
Allow script to be used as munin plugin.
-rwxr-xr-x | frikanalen/bin/tonostats | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/frikanalen/bin/tonostats b/frikanalen/bin/tonostats index 6ca57bc..ccc8db1 100755 --- a/frikanalen/bin/tonostats +++ b/frikanalen/bin/tonostats @@ -2,13 +2,14 @@ use strict; use warnings; +use vars qw(%opts); + +use Getopt::Std; # SOAP:Lite må modifiseres til å gjøre ting på MS måten :-/ use SOAP::Lite on_action => sub {sprintf '%s/%s', @_}, ; -sub print_tono_stats { - my $id = shift; - +sub get_tono_stats { my $soap = new SOAP::Lite -> uri('http://localhost/CommunitySiteService') -> proxy('http://communitysite1.frikanalen.tv/CommunitySiteFacade/CommunitySiteService.asmx'); @@ -32,8 +33,8 @@ sub print_tono_stats { unless ($res->{'Data'}) { return; } - my $tono; - my $notono; + my $tono = 0; + my $notono = 0; foreach my $video (@{$res->{'Data'}->{'Video'}}) { if ("true" eq $video->{'HasTonoRecords'}) { $tono++; @@ -41,10 +42,33 @@ sub print_tono_stats { $notono++; } } - print("Innslag med tono-musikk: $tono (", - int( 100 * $tono / ($tono+$notono)),"%)\n"); - print("Innslag uten tonon-musikk: $notono (", - int( 100 * $notono / ($tono+$notono)),"%)\n"); + return ($tono, $notono); +} +sub print_tono_stats { + my ($with, $without) = get_tono_stats(); + print("Innslag med tono-musikk: $with (", + int( 100 * $with / ($with+$without)),"%)\n"); + print("Innslag uten tonon-musikk: $without (", + int( 100 * $without / ($with+$without)),"%)\n"); +} +sub munin_plugin { + my @ARGV = @_; + if (defined $ARGV[0] && "config" eq $ARGV[0]) { + print <<EOF; +graph_title Fraction of events with Tono-related music +graph_category Frikanalen +tono_frac.label fraction +EOF + } else { + my ($with, $without) = get_tono_stats(); + printf "tono_frac.value %.3f\n", ($with / ($with + $without)); + } } -print_tono_stats(); +getopts("m", \%opts); + +if ($opts{'m'}) { + munin_plugin(@ARGV); +} else { + print_tono_stats(); +} |