Release Cubemap 1.4.3.
[cubemap] / munin / cubemap_input
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Munin::Plugin;
6
7 need_multigraph();
8
9 my $input_stats_filename = $ENV{"cubemap_input_stats"} // "/var/lib/cubemap/cubemap-input.stats";
10
11 my $mode = $ARGV[0] // "print";
12 if ($mode eq 'config') {
13         print "multigraph cubemap_input\n";
14         print "graph_title Cubemap inputs\n";
15         print "graph_category network\n";
16         print "graph_vlabel bits/sec\n";
17
18         print "multigraph cubemap_input_latency\n";
19         print "graph_title Cubemap input latency\n";
20         print "graph_category network\n";
21         print "graph_vlabel ms\n";
22 }
23
24 open my $stats, "<", $input_stats_filename
25         or die "$input_stats_filename: $!";
26 while (<$stats>) {
27         chomp;
28         my ($url, $bytes_received, $data_bytes_received, $connection_time, $metadata_bytes_received, $latency) =
29                 /^(\S+) (\d+) (\d+) (-|\d+) (\d+) (-|\d+\.\d+)/ or die "Invalid stats format";
30         my $stream_name = stream_name($url);
31         if ($mode eq 'config') {
32                 print "multigraph cubemap_input\n";
33                 print "${stream_name}.label Data input bitrate of $url\n";
34                 print "${stream_name}.type DERIVE\n";
35                 print "${stream_name}.min 0\n";
36                 print "multigraph cubemap_input_latency\n";
37                 print "${stream_name}.label Encoder-to-reflector latency $url (seconds)\n";
38                 print "${stream_name}.type GAUGE\n";
39                 print "${stream_name}.min 0\n";
40         } else {
41                 print "multigraph cubemap_input\n";
42                 printf "${stream_name}.value %d\n", $data_bytes_received * 8;
43                 if ($latency ne '-') {
44                         print "multigraph cubemap_input_latency\n";
45                         printf "${stream_name}.value %f\n", $latency * 1000;
46                 }
47         }
48 }
49 close $stats;
50         
51 sub stream_name {
52         my $stream = shift;
53         $stream =~ y/a-z0-9/_/c;
54         return $stream;
55 }