root / plugins / network / fms_apps_rate @ d7f54f3e
Historique | Voir | Annoter | Télécharger (9,49 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor rate of new connections in applications of Flash Media |
| 4 |
# Server. |
| 5 |
# |
| 6 |
# Parameters: |
| 7 |
# |
| 8 |
# config (required) |
| 9 |
# autoconf (optional - only used by munin-config) |
| 10 |
# |
| 11 |
# Requirements: |
| 12 |
# |
| 13 |
# libwww-perl (LWP) Perl library |
| 14 |
# Proc::ProcessTable Perl module |
| 15 |
# |
| 16 |
# Tested with: |
| 17 |
# Debian Etch |
| 18 |
# Macromedia Flash Media Server 2.0.3 r68 |
| 19 |
# Adobe Flash Media Server 3.0.1 r123 |
| 20 |
# Adobe Flash Media Server 3.5.0 r405 |
| 21 |
# |
| 22 |
# $Log$ |
| 23 |
# Revision 1.0 2009/01/25 05:07:23 muzso |
| 24 |
# Initial release. |
| 25 |
# |
| 26 |
# Usage |
| 27 |
# ----- |
| 28 |
# |
| 29 |
# 1. You will need the following Perl modules for this plugin to work: |
| 30 |
# |
| 31 |
# LWP - The World-Wide Web library for Perl |
| 32 |
# Used modules: HTTP::Request, LWP::Simple, LWP::UserAgent |
| 33 |
# http://search.cpan.org/perldoc?LWP |
| 34 |
# |
| 35 |
# Proc::ProcessTable - Perl extension to access the unix process table |
| 36 |
# http://search.cpan.org/perldoc?Proc::ProcessTable |
| 37 |
# |
| 38 |
# On a Debian/Ubuntu system: |
| 39 |
# apt-get install libwww-perl libproc-process-perl |
| 40 |
# |
| 41 |
# In Ubuntu and recent Debian (Lenny and later) versions the latter is |
| 42 |
# renamed to libproc-processtable-perl, but for now (at the time of |
| 43 |
# writing) libproc-process-perl still exists as a dummy package to provide |
| 44 |
# backward compatibility. |
| 45 |
# |
| 46 |
# 2. You've to publish the "getApps" and "getAppStats" commands of the |
| 47 |
# Flash Media Administration Server for use through the HTTP admin API. |
| 48 |
# This means that you've to set "USERS.HTTPCOMMAND_ALLOW" to "true" |
| 49 |
# in ${FMS_DIR}/conf/fms.ini and in ${FMS_DIR}/conf/Users.xml set the
|
| 50 |
# value of the node "Root/AdminServer/HTTPCommands/Allow" to contain |
| 51 |
# "getApps" and "getAppStats" too (by default it allows only "ping"). |
| 52 |
# |
| 53 |
# 3. If you want to monitor an FMS running locally (ie. on the same server |
| 54 |
# where this plugin is deployed), then the plugin will autoconfigure |
| 55 |
# itself by fetching parameters from the ${FMS_DIR}/conf/fms.ini config
|
| 56 |
# file of your FMS installation (autoconfigure will only work if the Flash |
| 57 |
# Media Administration Server is running since the plugin fetches the |
| 58 |
# location of the FMS directory through the current working directory of |
| 59 |
# the "fmsadmin" process). For this you have to run the plugin with root |
| 60 |
# privileges. To do so, specify in the Munin node plugin config file to |
| 61 |
# use "root" user for the plugin. |
| 62 |
# |
| 63 |
# On Debian/Ubuntu this file can be found at |
| 64 |
# /etc/munin/plugin-conf.d/munin-node |
| 65 |
# |
| 66 |
# The entry for the plugin should look like this: |
| 67 |
# [fms_apps] |
| 68 |
# user = root |
| 69 |
# |
| 70 |
# If autoconfiguration does not work or you want to specify the parameters |
| 71 |
# yourself (eg. you want to monitor an FMS that is on a different host), |
| 72 |
# then add a plugin entry to the Munin node plugin config file like this: |
| 73 |
# [fms_apps] |
| 74 |
# env.fms_admin_host = fms.example.com |
| 75 |
# env.fms_admin_port = 1111 |
| 76 |
# env.fms_admin_username = admin |
| 77 |
# env.fms_admin_password = the_admin_password |
| 78 |
# |
| 79 |
# For a local FMS the fms_admin_host can be set to "localhost". |
| 80 |
# |
| 81 |
# If you're using the env.fms_admin_* variables for configuration, then |
| 82 |
# the plugin does not require root privileges. |
| 83 |
# |
| 84 |
# However if doing so, it is strongly advised that you restrict access to |
| 85 |
# the Munin node plugin config file. It should be readable only by the |
| 86 |
# Munin node daemon since your FMS admin password should not be accessible |
| 87 |
# by any other user. |
| 88 |
# In case of Debian/Ubuntu the /etc/munin/plugin-conf.d/munin-node file |
| 89 |
# is owned by root and the munin-node process runs with root privileges, |
| 90 |
# so the correct permission is to have the file readable only by root. |
| 91 |
# |
| 92 |
# |
| 93 |
# |
| 94 |
# Note: in case something "bad" happens (eg. plugin is run as non-root and |
| 95 |
# autoconfiguration is used) the plugin writes some informative message |
| 96 |
# to stderr to make debugging easier. This should not affect the normal |
| 97 |
# operation of munin-node since only the stdout of the plugins is used |
| 98 |
# and that's always kept as munin-node expects. |
| 99 |
# |
| 100 |
# |
| 101 |
# |
| 102 |
# Magic markers (optional - used by munin-config and installation scripts): |
| 103 |
# |
| 104 |
#%# family=auto |
| 105 |
#%# capabilities=autoconf |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
use strict; |
| 110 |
use LWP::UserAgent; |
| 111 |
use LWP::Simple; |
| 112 |
use Proc::ProcessTable; |
| 113 |
|
| 114 |
my ($host, $port, $username, $password); |
| 115 |
|
| 116 |
sub name_filter { my ($n) = @_; $n =~ s/[^a-zA-Z0-9_]/_/g; $n }
|
| 117 |
|
| 118 |
sub get_apps {
|
| 119 |
my @applist; |
| 120 |
my $ua = LWP::UserAgent->new(timeout => 30); |
| 121 |
my $url = sprintf("http://%s:%d/admin/getApps?auser=%s\&apswd=%s", $host, $port, $username, $password);
|
| 122 |
|
| 123 |
my $response = $ua->request(HTTP::Request->new('GET', $url));
|
| 124 |
if ( $response->content =~ /<data>[^<]*(<.*>)[^>]*<\/data>/is ) {
|
| 125 |
my $apps = $1; |
| 126 |
while ( $apps =~ /<_[0-9]+> *([^<]*) *<\/_[0-9]+>/gi ) {
|
| 127 |
my $appname = $1; |
| 128 |
push(@applist, $appname); |
| 129 |
} |
| 130 |
} |
| 131 |
return @applist; |
| 132 |
} |
| 133 |
|
| 134 |
if ( defined($ENV{fms_admin_host}) and length($ENV{fms_admin_host}) > 0 ) {
|
| 135 |
$host = $ENV{fms_admin_host};
|
| 136 |
} |
| 137 |
if ( defined($ENV{fms_admin_port}) and length($ENV{fms_admin_port}) > 0 ) {
|
| 138 |
$port = $ENV{fms_admin_port};
|
| 139 |
} |
| 140 |
if ( defined($ENV{fms_admin_username}) and length($ENV{fms_admin_username}) > 0 ) {
|
| 141 |
$username = $ENV{fms_admin_username};
|
| 142 |
} |
| 143 |
if ( defined($ENV{fms_admin_password}) and length($ENV{fms_admin_password}) > 0 ) {
|
| 144 |
$password = $ENV{fms_admin_password};
|
| 145 |
} |
| 146 |
|
| 147 |
if ( !( defined($host) and defined($port) and defined($username) and defined($password) ) ) {
|
| 148 |
# Autoconfiguration: |
| 149 |
# 1. Find the "fmsadmin" process and assume that FMS is installed in the |
| 150 |
# current working directory of the process. |
| 151 |
# 2. Look for the FMS config file in ${FMS_DIR}/conf/fms.ini.
|
| 152 |
# 3. Fetch host, port, admin username and password values from the |
| 153 |
# config file. |
| 154 |
|
| 155 |
# check that plugin is running with root privileges |
| 156 |
if ( $> == 0 ) {
|
| 157 |
my $ProcTable = new Proc::ProcessTable; |
| 158 |
PROC_LOOP: foreach my $proc (@{$ProcTable->table}) {
|
| 159 |
# match any filename starting with "fmsadmin" |
| 160 |
# (this way the plugin might work on platforms other |
| 161 |
# than linux too) |
| 162 |
if ( defined($proc->{fname}) and $proc->{fname} =~ /^fmsadmin/i and defined($proc->{cwd}) ) {
|
| 163 |
my $fms_config = $proc->{cwd} . "/conf/fms.ini";
|
| 164 |
if ( open(my $fp, '<', $fms_config) ) {
|
| 165 |
while (my $line = <$fp>) {
|
| 166 |
chomp($line); |
| 167 |
if ( $line =~ /^ *SERVER\.ADMIN_USERNAME *= *([^ ].*) *$/ ) {
|
| 168 |
$username = $1; |
| 169 |
} elsif ( $line =~ /^ *SERVER\.ADMIN_PASSWORD *= *([^ ].*) *$/ ) {
|
| 170 |
$password = $1; |
| 171 |
} elsif ( $line =~ /^ *SERVER\.ADMINSERVER_HOSTPORT *= *([^ ]*)/ ) {
|
| 172 |
my @data = split(":", $1);
|
| 173 |
if ( $#data > 0 ) {
|
| 174 |
if ( defined($data[0]) and length($data[0]) > 0 ) {
|
| 175 |
$host = $data[0]; |
| 176 |
} else {
|
| 177 |
$host = "localhost"; |
| 178 |
} |
| 179 |
$port = $data[1]; |
| 180 |
} |
| 181 |
} |
| 182 |
# exit the loop if we've got all parameters |
| 183 |
last PROC_LOOP if defined($host) and defined($port) and defined($username) and defined($password); |
| 184 |
} |
| 185 |
} else {
|
| 186 |
print(STDERR "Can't open FMS config file (" . $fms_config . "): $!\n");
|
| 187 |
} |
| 188 |
# exit the loop since we've already found the process |
| 189 |
# that we were looking for, we just failed to find |
| 190 |
# all required parameters in fms.ini (or failed to |
| 191 |
# find fms.ini at all in (cwd of fmsadmin)/conf |
| 192 |
last PROC_LOOP; |
| 193 |
} |
| 194 |
} |
| 195 |
} else {
|
| 196 |
print(STDERR "Plugin must be run with root privileges for autoconfiguration to work!\n"); |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
if ( defined($ARGV[0]) ) {
|
| 201 |
if ( $ARGV[0] eq "autoconf" ) {
|
| 202 |
if ( defined($host) and defined($port) and defined($username) and defined($password) ) {
|
| 203 |
print("yes\n");
|
| 204 |
} else {
|
| 205 |
print("no\n");
|
| 206 |
} |
| 207 |
exit 0; |
| 208 |
} elsif ( $ARGV[0] eq "config" ) {
|
| 209 |
print <<'END_GRAPH_CONFIG'; |
| 210 |
graph_title Flash Media Server application connection rates |
| 211 |
graph_args -l 0 --base 1000 |
| 212 |
graph_vlabel new connections per ${graph_period}
|
| 213 |
graph_category network |
| 214 |
graph_period minute |
| 215 |
graph_info This graph shows the number of new connections per ${graph_period} for each application on the Flash Media Server.
|
| 216 |
END_GRAPH_CONFIG |
| 217 |
if ( defined($host) and defined($port) and defined($username) and defined($password) ) {
|
| 218 |
my @apps = get_apps(); |
| 219 |
if ( $#apps >= 0 ) {
|
| 220 |
foreach my $app (@apps) {
|
| 221 |
my $symbol = name_filter($app); |
| 222 |
print <<"END_APP_CONFIG"; |
| 223 |
fms_app_total_$symbol.label $app |
| 224 |
fms_app_total_$symbol.type DERIVE |
| 225 |
fms_app_total_$symbol.min 0 |
| 226 |
END_APP_CONFIG |
| 227 |
} |
| 228 |
exit 0; |
| 229 |
} else {
|
| 230 |
print(STDERR "Failed to get list of applications from the Flash Media Administration Server!\n"); |
| 231 |
exit 1; |
| 232 |
} |
| 233 |
} else {
|
| 234 |
print(STDERR "Failed to get all parameters needed for the connection to the Flash Media Administration Server!\n"); |
| 235 |
exit 1; |
| 236 |
} |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
if ( defined($host) and defined($port) and defined($username) and defined($password) ) {
|
| 241 |
my @apps = get_apps(); |
| 242 |
if ( $#apps >= 0 ) {
|
| 243 |
my $ua = LWP::UserAgent->new(timeout => 30); |
| 244 |
foreach my $app (@apps) {
|
| 245 |
my $symbol = name_filter($app); |
| 246 |
my $url = sprintf("http://%s:%d/admin/getAppStats?auser=%s\&apswd=%s\&app=%s", $host, $port, $username, $password, $app);
|
| 247 |
my $response = $ua->request(HTTP::Request->new('GET', $url));
|
| 248 |
if ( $response->content =~ /<data>.*<total_connects>[^0-9]*([0-9]+)[^0-9]*<\/total_connects>.*<\/data>/is ) {
|
| 249 |
print("fms_app_total_$symbol.value $1\n");
|
| 250 |
} else {
|
| 251 |
print(STDERR "Failed to get total number of played streams for the \"$app\" application from the Flash Media Administration Server!\n"); |
| 252 |
print("fms_app_total_$symbol.value U\n");
|
| 253 |
} |
| 254 |
} |
| 255 |
exit 0; |
| 256 |
} else {
|
| 257 |
print(STDERR "Failed to get list of applications from the Flash Media Administration Server!\n"); |
| 258 |
exit 1; |
| 259 |
} |
| 260 |
} else {
|
| 261 |
print(STDERR "Failed to get all parameters needed for the connection to the Flash Media Administration Server!\n"); |
| 262 |
exit 2; |
| 263 |
} |
| 264 |
|
