7 my $config_filename = $ENV{"cubemap_config"} // "/etc/cubemap.config";
8 my $stats_filename = $ENV{"cubemap_stats"} // "/var/lib/cubemap/cubemap.stats";
10 my $mode = $ARGV[0] // "print";
11 if ($mode eq 'config') {
12 print "graph_title Cubemap viewers\n";
13 print "graph_category network\n";
14 print "graph_vlabel viewers\n";
19 open my $config, "<", $config_filename
20 or die "$config_filename: $!";
23 /^stream (\S+) / or next;
25 $streams{$stream} = 0;
27 my $stream_name = stream_name($stream);
28 if ($mode eq 'config') {
29 print "${stream_name}.label Number of viewers of $stream\n";
30 print "${stream_name}.type GAUGE\n";
31 print "${stream_name}.min 0\n";
37 if ($mode eq 'config') {
38 print "total.label Total number of viewers\n";
39 print "total.type GAUGE\n";
40 print "total.min 0\n";
43 open my $stats, "<", $stats_filename
44 or die "$stats_filename: $!";
47 my ($ip, $fd, $mark, $stream, $connected_time, $bytes_sent, $loss_bytes, $loss_events) =
48 /^(\S+) (\d+) (\d+) (\S+) (\d+) (\d+) (\d+) (\d+)/ or die "Invalid stats format";
54 if ($mode ne 'config') {
55 for my $stream (sort keys %streams) {
56 my $stream_name = stream_name($stream);
57 printf "${stream_name}.value %d\n", $streams{$stream};
59 printf "total.value %d\n", $total;
64 $stream =~ y/a-z0-9/_/c;