Projet

Général

Profil

Révision d2350e0e

IDd2350e0ed6bb06ade80c4a8a53a8bc1381f933f5
Parent 37aedf65
Enfant 9176c668

Ajouté par Zsolt M?ller il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/fms_apps_rate
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 get_apps {
117
	my @applist;
118
	my $ua = LWP::UserAgent->new(timeout => 30);
119
	my $url = sprintf("http://%s:%d/admin/getApps?auser=%s\&apswd=%s", $host, $port, $username, $password);
120

  
121
	my $response = $ua->request(HTTP::Request->new('GET', $url));
122
	if ( $response->content =~ /<data>[^<]*(<.*>)[^>]*<\/data>/is ) {
123
		my $apps = $1;
124
		while ( $apps =~ /<_[0-9]+> *([^<]*) *<\/_[0-9]+>/gi ) {
125
			my $appname = $1;
126
			$appname =~ s/[^a-zA-Z0-9_]/_/g;
127
			push(@applist, $appname);
128
		}
129
	}
130
	return @applist;
131
}
132

  
133
if ( defined($ENV{fms_admin_host}) and length($ENV{fms_admin_host}) > 0 ) {
134
	$host = $ENV{fms_admin_host};
135
}
136
if ( defined($ENV{fms_admin_port}) and length($ENV{fms_admin_port}) > 0 ) {
137
	$port = $ENV{fms_admin_port};
138
}
139
if ( defined($ENV{fms_admin_username}) and length($ENV{fms_admin_username}) > 0 ) {
140
	$username = $ENV{fms_admin_username};
141
}
142
if ( defined($ENV{fms_admin_password}) and length($ENV{fms_admin_password}) > 0 ) {
143
	$password = $ENV{fms_admin_password};
144
}
145

  
146
if ( !( defined($host) and defined($port) and defined($username) and defined($password) ) ) {
147
	# Autoconfiguration:
148
	# 1. Find the "fmsadmin" process and assume that FMS is installed in the
149
	#    current working directory of the process.
150
	# 2. Look for the FMS config file in ${FMS_DIR}/conf/fms.ini.
151
	# 3. Fetch host, port, admin username and password values from the
152
	#    config file.
153
	
154
	# check that plugin is running with root privileges
155
	if ( $> == 0 ) {
156
		my $ProcTable = new Proc::ProcessTable;
157
		PROC_LOOP: foreach my $proc (@{$ProcTable->table}) {
158
			# match any filename starting with "fmsadmin"
159
			# (this way the plugin might work on platforms other
160
			#  than linux too)
161
			if ( defined($proc->{fname}) and $proc->{fname} =~ /^fmsadmin/i and defined($proc->{cwd}) ) {
162
				my $fms_config = $proc->{cwd} . "/conf/fms.ini";
163
				if ( open(my $fp, '<', $fms_config) ) {
164
					while (my $line = <$fp>) {
165
						chomp($line);
166
						if ( $line =~ /^ *SERVER\.ADMIN_USERNAME *= *([^ ].*) *$/ ) {
167
							$username = $1;
168
						} elsif ( $line =~ /^ *SERVER\.ADMIN_PASSWORD *= *([^ ].*) *$/ ) {
169
							$password = $1;
170
						} elsif ( $line =~ /^ *SERVER\.ADMINSERVER_HOSTPORT *= *([^ ]*)/ ) {
171
							my @data = split(":", $1);
172
							if ( $#data > 0 ) {
173
								if ( defined($data[0]) and length($data[0]) > 0 ) {
174
									$host = $data[0];
175
								} else {
176
									$host = "localhost";
177
								}
178
								$port = $data[1];
179
							}
180
						}
181
						# exit the loop if we've got all parameters
182
						last PROC_LOOP if defined($host) and defined($port) and defined($username) and defined($password);
183
					}
184
				} else {
185
					print(STDERR "Can't open FMS config file (" . $fms_config . "): $!\n");
186
				}
187
				# exit the loop since we've already found the process
188
				# that we were looking for, we just failed to find
189
				# all required parameters in fms.ini (or failed to
190
				# find fms.ini at all in (cwd of fmsadmin)/conf
191
				last PROC_LOOP;
192
			}
193
		}
194
	} else {
195
		print(STDERR "Plugin must be run with root privileges for autoconfiguration to work!\n");
196
	}
197
}
198

  
199
if ( defined($ARGV[0]) ) {
200
	if ( $ARGV[0] eq "autoconf" ) {
201
		if ( defined($host) and defined($port) and defined($username) and defined($password) ) {
202
			print("yes\n");
203
			exit 0;
204
		} else {
205
			print("no\n");
206
			exit 1;
207
		}
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
					print <<"END_APP_CONFIG";
222
fms_app_total_$app.label $app
223
fms_app_total_$app.type DERIVE
224
fms_app_total_$app.min 0
225
END_APP_CONFIG
226
				}
227
				exit 0;
228
			} else {
229
				print(STDERR "Failed to get list of applications from the Flash Media Administration Server!\n");
230
				exit 1;
231
			}
232
		} else {
233
			print(STDERR "Failed to get all parameters needed for the connection to the Flash Media Administration Server!\n");
234
			exit 1;
235
		}
236
	}
237
}
238

  
239
if ( defined($host) and defined($port) and defined($username) and defined($password) ) {
240
	my @apps = get_apps();
241
	if ( $#apps >= 0 ) {
242
		my $ua = LWP::UserAgent->new(timeout => 30);
243
		foreach my $app (@apps) {
244
			my $url = sprintf("http://%s:%d/admin/getAppStats?auser=%s\&apswd=%s\&app=%s", $host, $port, $username, $password, $app);
245
			my $response = $ua->request(HTTP::Request->new('GET', $url));
246
			if ( $response->content =~ /<data>.*<total_connects>[^0-9]*([0-9]+)[^0-9]*<\/total_connects>.*<\/data>/is ) {
247
				print("fms_app_total_$app.value $1\n");
248
			} else {
249
				print(STDERR "Failed to get total number of played streams for the \"$app\" application from the Flash Media Administration Server!\n");
250
				print("fms_app_total_$app.value U\n");
251
			}
252
		}
253
		exit 0;
254
	} else {
255
		print(STDERR "Failed to get list of applications from the Flash Media Administration Server!\n");
256
		exit 1;
257
	}
258
} else {
259
	print(STDERR "Failed to get all parameters needed for the connection to the Flash Media Administration Server!\n");
260
	exit 2;
261
}
262

  

Formats disponibles : Unified diff