Add latency statistics to the Munin plugin.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 22 Jul 2016 22:41:26 +0000 (00:41 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 22 Jul 2016 22:45:08 +0000 (00:45 +0200)
munin/cubemap_input

index 21b453d..36ac0b4 100755 (executable)
@@ -4,28 +4,46 @@ use strict;
 use warnings;
 use Munin::Plugin;
 
+need_multigraph();
+
 my $input_stats_filename = $ENV{"cubemap_input_stats"} // "/var/lib/cubemap/cubemap-input.stats";
 
 my $mode = $ARGV[0] // "print";
 if ($mode eq 'config') {
+       print "multigraph cubemap_input\n";
        print "graph_title Cubemap inputs\n";
        print "graph_category network\n";
        print "graph_vlabel bits/sec\n";
+
+       print "multigraph cubemap_input_latency\n";
+       print "graph_title Cubemap input latency\n";
+       print "graph_category network\n";
+       print "graph_vlabel ms\n";
 }
 
 open my $stats, "<", $input_stats_filename
        or die "$input_stats_filename: $!";
 while (<$stats>) {
        chomp;
-       my ($url, $bytes_received, $data_bytes_received, $connection_time) =
-               /^(\S+) (\d+) (\d+) (-|\d+)/ or die "Invalid stats format";
+       my ($url, $bytes_received, $data_bytes_received, $connection_time, $metadata_bytes_received, $latency) =
+               /^(\S+) (\d+) (\d+) (-|\d+) (\d+) (-|\d+\.\d+)/ or die "Invalid stats format";
        my $stream_name = stream_name($url);
        if ($mode eq 'config') {
+               print "multigraph cubemap_input\n";
                print "${stream_name}.label Data input bitrate of $url\n";
                print "${stream_name}.type DERIVE\n";
                print "${stream_name}.min 0\n";
+               print "multigraph cubemap_input_latency\n";
+               print "${stream_name}.label Encoder-to-reflector latency $url (seconds)\n";
+               print "${stream_name}.type GAUGE\n";
+               print "${stream_name}.min 0\n";
        } else {
+               print "multigraph cubemap_input\n";
                printf "${stream_name}.value %d\n", $data_bytes_received * 8;
+               if ($latency ne '-') {
+                       print "multigraph cubemap_input_latency\n";
+                       printf "${stream_name}.value %f\n", $latency * 1000;
+               }
        }
 }
 close $stats;