00b6ec37513ed9432a1a6cbf33865250b0e64f8a
[cubemap] / munin / cubemap_input
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Munin::Plugin;
6
7 my $input_stats_filename = $ENV{"cubemap_input_stats"} // "/var/lib/cubemap/cubemap-input.stats";
8
9 my $mode = $ARGV[0] // "print";
10 if ($mode eq 'config') {
11         print "graph_title Cubemap inputs\n";
12         print "graph_category network\n";
13         print "graph_vlabel viewers\n";
14 }
15
16 open my $stats, "<", $input_stats_filename
17         or die "$input_stats_filename: $!";
18 while (<$stats>) {
19         chomp;
20         my ($url, $bytes_received, $data_bytes_received, $connection_time) =
21                 /^(\S+) (\d+) (\d+) (-|\d+)/ or die "Invalid stats format";
22         my $stream_name = stream_name($url);
23         if ($mode eq 'config') {
24                 print "${stream_name}.label Data input bitrate of $url\n";
25                 print "${stream_name}.type DERIVE\n";
26                 print "${stream_name}.min 0\n";
27         } else {
28                 printf "${stream_name}.value %d\n", $data_bytes_received * 8;
29         }
30 }
31 close $stats;
32         
33 sub stream_name {
34         my $stream = shift;
35         $stream =~ y/a-z0-9/_/c;
36         return $stream;
37 }