]> git.sesse.net Git - cubemap/commitdiff
Include a Munin plugin that was missing in the archive.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 24 Aug 2013 15:58:02 +0000 (17:58 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 24 Aug 2013 15:58:18 +0000 (17:58 +0200)
.gitignore
munin/cubemap [new file with mode: 0755]

index aa8fde8410e66505a124ca726baa4cb7aa1edf49..cba1f96579ba8ed185a531203a69f20595078c04 100644 (file)
@@ -1,4 +1,5 @@
 cubemap
 cubemap
+!munin/cubemap
 *.o
 *.d
 *.pb.cc
 *.o
 *.d
 *.pb.cc
diff --git a/munin/cubemap b/munin/cubemap
new file mode 100755 (executable)
index 0000000..8079d6e
--- /dev/null
@@ -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;
+}