From: Steinar H. Gunderson Date: Sat, 24 Aug 2013 15:58:02 +0000 (+0200) Subject: Include a Munin plugin that was missing in the archive. X-Git-Tag: 1.0.0~1 X-Git-Url: https://git.sesse.net/?p=cubemap;a=commitdiff_plain;h=c2c0b5f5eb8a04a61d9c861b3cb0946043a25f0e Include a Munin plugin that was missing in the archive. --- diff --git a/.gitignore b/.gitignore index aa8fde8..cba1f96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ cubemap +!munin/cubemap *.o *.d *.pb.cc diff --git a/munin/cubemap b/munin/cubemap new file mode 100755 index 0000000..8079d6e --- /dev/null +++ b/munin/cubemap @@ -0,0 +1,66 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use Munin::Plugin; + +my $config_filename = $ENV{"cubemap_config"} // "/etc/cubemap.config"; +my $stats_filename = $ENV{"cubemap_stats"} // "/var/lib/cubemap/cubemap.stats"; + +my $mode = $ARGV[0] // "print"; +if ($mode eq 'config') { + print "graph_title Cubemap viewers\n"; + print "graph_category network\n"; + print "graph_vlabel viewers\n"; +} + +my %streams = (); + +open my $config, "<", $config_filename + or die "$config_filename: $!"; +while (<$config>) { + chomp; + /^stream (\S+) / or next; + my $stream = $1; + $streams{$stream} = 0; + + my $stream_name = stream_name($stream); + if ($mode eq 'config') { + print "${stream_name}.label Number of viewers of $stream\n"; + print "${stream_name}.type GAUGE\n"; + print "${stream_name}.min 0\n"; + } +} +close $config; + +my $total = 0; +if ($mode eq 'config') { + print "total.label Total number of viewers\n"; + print "total.type GAUGE\n"; + print "total.min 0\n"; +} + +open my $stats, "<", $stats_filename + or die "$stats_filename: $!"; +while (<$stats>) { + chomp; + my ($ip, $fd, $mark, $stream, $connected_time, $bytes_sent, $loss_bytes, $loss_events) = + /^(\S+) (\d+) (\d+) (\S+) (\d+) (\d+) (\d+) (\d+)/ or die "Invalid stats format"; + ++$streams{$stream}; + ++$total; +} +close $stats; + +if ($mode ne 'config') { + for my $stream (sort keys %streams) { + my $stream_name = stream_name($stream); + printf "${stream_name}.value %d\n", $streams{$stream}; + } + printf "total.value %d\n", $total; +} + +sub stream_name { + my $stream = shift; + $stream =~ y/a-z0-9/_/c; + return $stream; +}