/usr/share/munin/plugins/cubemap is in cubemap 1.3.2-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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;
}
|