# On a Debian/Ubuntu system you can install this with the following command
# (if APT is configured properly):
# apt-get install libproc-process-perl
#
# In Ubuntu and recent Debian (Lenny and later) versions this is renamed to
# libproc-processtable-perl, but for now (at the time of writing)
# libproc-process-perl still exists as a dummy package to provide backward
# compatibility.
#
# If you're using the default statistic fetching method (the call to the FMS
# Admin Server HTTP API), then you'll also need the following Perl module:
#
# LWP - The World-Wide Web library for Perl
# Used modules: HTTP::Request, LWP::Simple, LWP::UserAgent
# http://search.cpan.org/perldoc?LWP
#
# On a Debian/Ubuntu system you can install this with the following command
# (if APT is configured properly):
# apt-get install libwww-perl
#
# For access to the FMS Admin HTTP API you've to publish the "getServerStats()"
# call. This means that you've to set "USERS.HTTPCOMMAND_ALLOW" to "true" in
# ${FMS_DIR}/conf/fms.ini and in ${FMS_DIR}/conf/Users.xml set the value of the
# node "Root/AdminServer/HTTPCommands/Allow" to contain "getServerStats" too
# (by default it allows only "ping").
#
# That's all you've to know about the default (autoconfiguration) method of
# running this plugin.
#
#
# As for manual configuration ...
#
# Follow this example plugin entry in the Munin node plugin config to specify
# the FMS Admin server parameters:
# [fms]
# env.fms_admin_host localhost
# env.fms_admin_port 1111
# env.fms_admin_username admin
# env.fms_admin_password the_admin_password
#
# Usually fms_admin_host will be localhost (since most people want to monitor
# a local instance of FMS), but of course you can set it to any hostname.
#
# It is strongly advised that you restrict access to the Munin node plugin
# config file. It should be readable only by the Munin node daemon since your
# FMS admin password should not be accessible by any other user.
# In case of Debian/Ubuntu the /etc/munin/plugin-conf.d/munin-node file is
# owned by root and the munin-node process runs with root privileges, so the
# correct permission is to have the file readable only by root.
#
# Manual configuration of the netstat method requires the following Munin node
# plugin config:
# [fms]
# env.use_netstat yes
# env.fms_host 192.168.0.1
# env.fms_port 1935
#
# The fms_host variable can be skipped if your FMS server listens on all IPs
# and not just a single IP.
# The fms_port variable must contain a comma-separated list of TCP ports that
# your FMS server listens on for incoming connections.
# In a default FMS installation this is the 1935 TCP port, but it can be
# an arbitrary list (eg. 1935,80,443).
#
#
# Note: autoconfiguration works by going through the list of running processes
# and looking for the "fmsadmin" process. If found, we check for the
# existence of the "conf/fms.ini" file in the current working directory
# of the process. This works fine for all tested FMS versions.
# However it is possible that this method is not "universal" enough
# (and it requires the plugin to be run as root too) so using the manual
# configuration is always there as a backup solution.
# The manual config method does not require root privileges for the plugin
# to work.
#
# In case something "bad" happens (eg. plugin is run as non-root and
# autoconfiguration is used) the plugin writes some informative message
# to stderr to make debugging easier. This should not affect the normal
# operation of munin-node since only the stdout of the plugins is used
# and that's always kept as munin-node expects.
#
#
#
# Magic markers (optional - used by munin-config and installation scripts):
#
#%# family=auto
#%# capabilities=autoconf
use strict;
use LWP::UserAgent;
use LWP::Simple;
use Proc::ProcessTable;
if ( defined($ARGV[0]) and $ARGV[0] eq "config" ) {
print <<'END_CONFIG';
graph_title Flash Media Server socket connections
graph_args -l 0 --base 1000
graph_vlabel active connections
graph_category network
graph_period second
graph_info This graph shows the number of active socket connections to the Flash Media Server.
fmserv_c.label connections
fmserv_c.type GAUGE
fmserv_c.min 0
END_CONFIG
exit 0;
}
my ($usenetstat, $fmshost, $fmsport, $adminhost, $adminport, $adminusername, $adminpassword);
if ( defined($ENV{use_netstat}) and length($ENV{use_netstat}) > 0 and lc($ENV{use_netstat}) ne "no") {
$usenetstat = "yes";
} else {
$usenetstat = "no";
}
if ( defined($ENV{fms_host}) and length($ENV{fms_host}) > 0 ) {
$fmshost = $ENV{fms_host};
}
if ( defined($ENV{fms_port}) and length($ENV{fms_port}) > 0 ) {
$fmsport = $ENV{fms_port};
}
if ( defined($ENV{fms_admin_host}) and length($ENV{fms_admin_host}) > 0 ) {
$adminhost = $ENV{fms_admin_host};
}
if ( defined($ENV{fms_admin_port}) and length($ENV{fms_admin_port}) > 0 ) {
$adminport = $ENV{fms_admin_port};
}
if ( defined($ENV{fms_admin_username}) and length($ENV{fms_admin_username}) > 0 ) {
$adminusername = $ENV{fms_admin_username};
}
if ( defined($ENV{fms_admin_password}) and length($ENV{fms_admin_password}) > 0 ) {
$adminpassword = $ENV{fms_admin_password};
}
if ( !( ( $usenetstat eq "yes" and defined($fmshost) and defined($fmsport) ) or ( $usenetstat eq "no" and defined($adminhost) and defined($adminport) and defined($adminusername) and defined($adminpassword) ) ) ) {
# Autoconfiguration:
# 1. Find the "fmsadmin" process and assume that FMS is installed in the
# current working directory of the process.
# 2. Look for the FMS config file in ${FMS_DIR}/conf/fms.ini.
# 3. Fetch host, port, admin username and password values from the
if ( defined($data[0]) and length($data[0]) > 0 ) {
$fmshost = $data[0];
} else {
$fmshost = "";
}
$fmsport = $data[1];
}
}
# exit the loop if we've got all parameters
last PROC_LOOP if ( $usenetstat eq "yes" and defined($fmshost) and defined($fmsport) ) or ( $usenetstat eq "no" and defined($adminhost) and defined($adminport) and defined($adminusername) and defined($adminpassword) );
# exit the loop since we've already found the process
# that we were looking for, we just failed to find
# all required parameters in fms.ini (or failed to
# find fms.ini at all in (cwd of fmsadmin)/conf
last PROC_LOOP;
}
}
} else {
print(STDERR "Plugin must be run with root privileges for autoconfiguration to work!\n");
}
}
if ( defined($ARGV[0]) and $ARGV[0] eq "autoconf" ) {
if ( ( $usenetstat eq "yes" and defined($fmshost) and defined($fmsport) ) or ( $usenetstat eq "no" and defined($adminhost) and defined($adminport) and defined($adminusername) and defined($adminpassword) ) ) {
print("yes\n");
exit 0;
} else {
print("no\n");
exit 1;
}
}
if ( $usenetstat eq "yes" and defined($fmshost) and defined($fmsport) ) {
$fmsport =~ s/,/|/g;
my $sockets = `netstat -n`;
my $regex = ":(" . $fmsport . ")[^0-9]+[^:]*:[0-9]+[^0-9]+.*ESTABLISHED";
if ( defined($fmshost) and length($fmshost) > 0 ) {
$fmshost =~ s/\./\\./g;
$regex = $fmshost . $regex;
}
my $count = 0;
while ( $sockets =~ /$regex/g ) {
$count++;
}
print("fmserv_c.value ${count}\n");
} elsif ( $usenetstat eq "no" and defined($adminhost) and defined($adminport) and defined($adminusername) and defined($adminpassword) ) {
my $ua = LWP::UserAgent->new(timeout => 30);
my $url = sprintf("http://%s:%d/admin/getServerStats?auser=%s\&apswd=%s", $adminhost, $adminport, $adminusername, $adminpassword);
my $response = $ua->request(HTTP::Request->new('GET', $url));
if ( $response->content =~ /<io>.*<connected>[^0-9]*([0-9]+)[^0-9]*<\/connected>.*<\/io>/is ) {
print("fmserv_c.value $1\n");
} else {
print("fmserv_c.value U\n");
}
} else {
print(STDERR "Failed to get all parameters needed for the connection to the Flash Media Administration Server!\n");