Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / php / php_fpm_process @ 09b88141

Historique | Voir | Annoter | Télécharger (5,79 ko)

1 c0e3ed7f minitux
#!/usr/bin/perl
2
# -*- cperl -*-
3
4
=head1 NAME
5
6 4528900a Calle Kabo
php_fpm_process - Munin plugin to show number of number of use processes on php-fpm.
7 c0e3ed7f minitux
8
9
Inspirated by php5-fpm_status plugin by Daniel Caillibaud
10
11
=head1 APPLICABLE SYSTEMS
12
13 f8bf3961 Raphaël Droz
Any php-fpm host
14
You will need the perl fastcgi::client on your host
15 c0e3ed7f minitux
16
=head1 CONFIGURATION
17
18 f8bf3961 Raphaël Droz
You have to put this in your plugin.conf.d folder
19 c0e3ed7f minitux
20 09b88141 Lars Kruse
In case your php process is listening on TCP:
21
22
   [php_fpm_process]
23 c0e3ed7f minitux
   env.serveraddr 127.0.0.1
24
   env.port 9000
25 f8bf3961 Raphaël Droz
   env.path /status
26 c0e3ed7f minitux
27 09b88141 Lars Kruse
28
In case your php process is listening on a Unix Socket:
29
30
   [php_fpm_process]
31 101c1f7c Olivier Mehani
   env.sock /var/run/php-fpm.sock
32 f8bf3961 Raphaël Droz
   env.path /status
33 926c0ee4 Vincent Viallet
34 c0e3ed7f minitux
=head1 MAGIC MARKERS
35
36
  #%# family=auto
37
  #%# capabilities=autoconf
38
39
=head1 VERSION
40
41 101c1f7c Olivier Mehani
  v2.0.0
42 c0e3ed7f minitux
43
=head1 AUTHOR
44
45 f8bf3961 Raphaël Droz
Minitux
46 09b88141 Lars Kruse
47 101c1f7c Olivier Mehani
Olivier Mehani <shtrom+munin@ssji.net>
48 c0e3ed7f minitux
49
=head1 LICENSE
50
51 101c1f7c Olivier Mehani
SPDX-License-Identifier: GPL-3.0
52 c0e3ed7f minitux
53
=cut
54
55 f8bf3961 Raphaël Droz
use File::Basename;
56 c0e3ed7f minitux
use FCGI::Client;
57
58
my $ish = 1;
59
my $header = "";
60
my $body = "";
61
my $IDLE = 0;
62
my $ACTIVE = 0;
63
my $TOTAL = 0;
64 101c1f7c Olivier Mehani
my $LISTEN = 0;
65
my $MAX = 0;
66
my $LEN = 0;
67
my $CONNECTIONS = 0;
68 f8bf3961 Raphaël Droz
my $SLOW_REQUESTS = 0;
69
my $PLUGIN_NAME = basename($0);
70 c0e3ed7f minitux
71
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
72
my $PORT = $ENV{'port'} || "9000";
73
my $PATH = $ENV{'path'} || "/status";
74 926c0ee4 Vincent Viallet
my $UNIX_SOCK = $ENV{'sock'};
75
76
my $sock;
77
78
if ($UNIX_SOCK) {
79 101c1f7c Olivier Mehani
	use IO::Socket::UNIX;
80
	$sock = IO::Socket::UNIX->new(
81
		Peer =>  $UNIX_SOCK,
82
	);
83
	if (!$sock) {
84
		print "Server maybe down, unabled to connect to $UNIX_SOCK";
85
		exit 2;
86
	}
87 926c0ee4 Vincent Viallet
} else {
88 101c1f7c Olivier Mehani
	use IO::Socket::INET;
89
	$sock = IO::Socket::INET->new(
90
		PeerAddr =>  $SERVERADDR,
91
		PeerPort =>  $PORT,
92
	);
93
	if (!$sock) {
94
		print "Server maybe down, unabled to connect to $SERVERADDR:$PORT";
95
		exit 2;
96
	}
97 c0e3ed7f minitux
}
98
99 926c0ee4 Vincent Viallet
my $client = FCGI::Client::Connection->new( sock => $sock );
100
101 f8bf3961 Raphaël Droz
my ( $stdout, $stderr, $appstatus )  = $client->request(
102 101c1f7c Olivier Mehani
	+{
103
		REQUEST_METHOD => 'GET',
104
		SCRIPT_FILENAME => '',
105
		QUERY_STRING => '',
106
		SCRIPT_NAME    => $PATH,
107
	},
108
	''
109
);
110
111
#
112
# Example output:
113
#
114
# pool:                 www
115
# process manager:      dynamic
116
# start time:           23/Jun/2019:12:13:50 +0200
117
# start since:          577793
118
# accepted conn:        37211
119
# listen queue:         0
120
# max listen queue:     0
121
# listen queue len:     0
122
# idle processes:       6
123
# active processes:     1
124
# total processes:      7
125
# max active processes: 13
126
# max children reached: 0
127
# slow requests:        0
128
129
#
130
# ...with ?full added to the query string, each child is also described:
131
#
132
# ************************
133
# pid:                  56027
134
# state:                Running
135
# start time:           18/Jul/2019:01:02:15 +0200
136
# start since:          45279
137
# requests:             776
138
# request duration:     1043
139
# request method:       GET
140
# request URI:          /fpm-status?full
141
# content length:       0
142
# user:                 -
143
# script:               -
144
# last request cpu:     0.00
145
# last request memory:  0
146
#
147 c0e3ed7f minitux
148
$stdout =~ s/\r//g;
149
150
while($stdout =~ /([^\n]*)\n?/g) {
151 101c1f7c Olivier Mehani
	if(!$1) {
152
		$ish = 0;
153
		next;
154
	}
155
	if($ish == 1) {
156
		$header .= $1."\n";
157
	} else {
158
		$body .= $1."\n";
159
	}
160 4528900a Calle Kabo
}
161
162
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
163
{
164 f8bf3961 Raphaël Droz
165 101c1f7c Olivier Mehani
	if($body =~ m/pool:\s+(.*?)\n/) {
166
		$pool = $1;
167
	}
168 4528900a Calle Kabo
169 101c1f7c Olivier Mehani
	print <<"EOF";
170 f8bf3961 Raphaël Droz
multigraph ${PLUGIN_NAME}_process
171 101c1f7c Olivier Mehani
graph_title php-fpm processes for $pool
172 f8bf3961 Raphaël Droz
graph_args --base 1000 -l 0
173
graph_vlabel Processes
174
graph_scale yes
175 101c1f7c Olivier Mehani
graph_category appserver
176
graph_info This graph shows the php-fpm process manager status from pool $pool
177 f8bf3961 Raphaël Droz
active.label Active processes
178
active.type GAUGE
179
active.draw AREA
180
active.info The number of active processes
181
idle.label Idle processes
182
idle.type GAUGE
183
idle.draw STACK
184
idle.info The number of idle processes
185
total.label Total processes
186
total.type GAUGE
187
total.draw LINE2
188
total.info The number of idle + active processes
189 101c1f7c Olivier Mehani
max.label Max processes
190
max.type GAUGE
191
max.draw LINE
192
max.info The maximum number of active processes since FPM has started
193 f8bf3961 Raphaël Droz
194 101c1f7c Olivier Mehani
multigraph ${PLUGIN_NAME}_queues
195
graph_title php-fpm queues for $pool
196 f8bf3961 Raphaël Droz
graph_args --base 1000 -l 0
197 101c1f7c Olivier Mehani
graph_vlabel Queue
198 f8bf3961 Raphaël Droz
graph_scale yes
199 101c1f7c Olivier Mehani
graph_category appserver
200
graph_info This graph shows the php-fpm queue from pool $pool
201
listen.label Listen queue
202
listen.type GAUGE
203
listen.draw LINE
204
listen.info The number of pending requests in the queue
205
max.label Max listen queue
206
max.type GAUGE
207
max.draw LINE
208
max.info The maximum number of pending requests in the queue
209
len.label Queue len
210
len.type GAUGE
211
len.draw LINE
212
len.info The number of pending connections in the queue
213
214
multigraph ${PLUGIN_NAME}_requests
215
graph_title php-fpm requests for $pool
216
graph_args --base 1000 -l 0
217
graph_vlabel Requests
218
graph_scale yes
219
graph_category appserver
220
graph_info This graph shows the php-fpm request rate from pool $pool
221
connections.label Connections
222
connections.type DERIVE
223
connections.draw LINE
224
connections.min 0
225
connections.info evolution of connections
226
slow.label Slow requests
227
slow.type DERIVE
228
slow.draw LINE
229
slow.min 0
230
slow.info evolution of slow requests (longer than request_slowlog_timeout)
231 f8bf3961 Raphaël Droz
232
EOF
233
234 101c1f7c Olivier Mehani
	exit 0
235 f8bf3961 Raphaël Droz
}
236 926c0ee4 Vincent Viallet
237 f8bf3961 Raphaël Droz
# print $body;
238
239
print "multigraph ${PLUGIN_NAME}_process\n";
240 c0e3ed7f minitux
241
if($body =~ m/idle processes: (.*?)\n/) {
242 101c1f7c Olivier Mehani
	$IDLE = $1;
243
	print "idle.value ".$IDLE."\n";
244 c0e3ed7f minitux
}
245
if($body =~ m/active processes: (.*?)\n/) {
246 101c1f7c Olivier Mehani
	$ACTIVE = $1;
247
	print "active.value ".$ACTIVE."\n";
248 c0e3ed7f minitux
}
249
if($body =~ m/total processes: (.*?)\n/) {
250 101c1f7c Olivier Mehani
	$TOTAL = $1;
251
	print "total.value ".$TOTAL."\n";
252
}
253
if($body =~ m/max active processes: (.*?)\n/) {
254
	$MAX = $1;
255
	print "max.value ".$MAX."\n";
256 c0e3ed7f minitux
}
257 f8bf3961 Raphaël Droz
258 101c1f7c Olivier Mehani
if($body =~ m/listen queue: (.*?)\n/) {
259
	$LISTEN= $1;
260
	print "multigraph ${PLUGIN_NAME}_queues\n";
261
	print "listen.value ".$LISTEN."\n";
262
	if($body =~ m/max listen queue: (.*?)\n/) {
263
		$MAX = $1;
264
		print "max.value ".$MAX."\n";
265
	}
266
	if($body =~ m/listen queue len: (.*?)\n/) {
267
		$LEN = $1;
268
		print "len.value ".$LEN."\n";
269
	}
270
}
271
272
print "multigraph ${PLUGIN_NAME}_requests\n";
273
if($body =~ m/accepted conn: (.*?)\n/) {
274
	$CONNECTIONS = $1;
275
	print "connections.value ".$CONNECTIONS."\n";
276
}
277 f8bf3961 Raphaël Droz
if($body =~ m/slow requests: (.*?)\n/) {
278 101c1f7c Olivier Mehani
	$SLOW_REQUESTS = $1;
279
	print "slow.value ".$SLOW_REQUESTS."\n";
280 f8bf3961 Raphaël Droz
}