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
#!/usr/bin/perl
2
# -*- cperl -*-
3

    
4
=head1 NAME
5

    
6
php_fpm_process - Munin plugin to show number of number of use processes on php-fpm.
7

    
8

    
9
Inspirated by php5-fpm_status plugin by Daniel Caillibaud
10

    
11
=head1 APPLICABLE SYSTEMS
12

    
13
Any php-fpm host
14
You will need the perl fastcgi::client on your host
15

    
16
=head1 CONFIGURATION
17

    
18
You have to put this in your plugin.conf.d folder
19

    
20
In case your php process is listening on TCP:
21

    
22
   [php_fpm_process]
23
   env.serveraddr 127.0.0.1
24
   env.port 9000
25
   env.path /status
26

    
27

    
28
In case your php process is listening on a Unix Socket:
29

    
30
   [php_fpm_process]
31
   env.sock /var/run/php-fpm.sock
32
   env.path /status
33

    
34
=head1 MAGIC MARKERS
35

    
36
  #%# family=auto
37
  #%# capabilities=autoconf
38

    
39
=head1 VERSION
40

    
41
  v2.0.0
42

    
43
=head1 AUTHOR
44

    
45
Minitux
46

    
47
Olivier Mehani <shtrom+munin@ssji.net>
48

    
49
=head1 LICENSE
50

    
51
SPDX-License-Identifier: GPL-3.0
52

    
53
=cut
54

    
55
use File::Basename;
56
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
my $LISTEN = 0;
65
my $MAX = 0;
66
my $LEN = 0;
67
my $CONNECTIONS = 0;
68
my $SLOW_REQUESTS = 0;
69
my $PLUGIN_NAME = basename($0);
70

    
71
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
72
my $PORT = $ENV{'port'} || "9000";
73
my $PATH = $ENV{'path'} || "/status";
74
my $UNIX_SOCK = $ENV{'sock'};
75

    
76
my $sock;
77

    
78
if ($UNIX_SOCK) {
79
	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
} else {
88
	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
}
98

    
99
my $client = FCGI::Client::Connection->new( sock => $sock );
100

    
101
my ( $stdout, $stderr, $appstatus )  = $client->request(
102
	+{
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

    
148
$stdout =~ s/\r//g;
149

    
150
while($stdout =~ /([^\n]*)\n?/g) {
151
	if(!$1) {
152
		$ish = 0;
153
		next;
154
	}
155
	if($ish == 1) {
156
		$header .= $1."\n";
157
	} else {
158
		$body .= $1."\n";
159
	}
160
}
161

    
162
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
163
{
164

    
165
	if($body =~ m/pool:\s+(.*?)\n/) {
166
		$pool = $1;
167
	}
168

    
169
	print <<"EOF";
170
multigraph ${PLUGIN_NAME}_process
171
graph_title php-fpm processes for $pool
172
graph_args --base 1000 -l 0
173
graph_vlabel Processes
174
graph_scale yes
175
graph_category appserver
176
graph_info This graph shows the php-fpm process manager status from pool $pool
177
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
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

    
194
multigraph ${PLUGIN_NAME}_queues
195
graph_title php-fpm queues for $pool
196
graph_args --base 1000 -l 0
197
graph_vlabel Queue
198
graph_scale yes
199
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

    
232
EOF
233

    
234
	exit 0
235
}
236

    
237
# print $body;
238

    
239
print "multigraph ${PLUGIN_NAME}_process\n";
240

    
241
if($body =~ m/idle processes: (.*?)\n/) {
242
	$IDLE = $1;
243
	print "idle.value ".$IDLE."\n";
244
}
245
if($body =~ m/active processes: (.*?)\n/) {
246
	$ACTIVE = $1;
247
	print "active.value ".$ACTIVE."\n";
248
}
249
if($body =~ m/total processes: (.*?)\n/) {
250
	$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
}
257

    
258
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
if($body =~ m/slow requests: (.*?)\n/) {
278
	$SLOW_REQUESTS = $1;
279
	print "slow.value ".$SLOW_REQUESTS."\n";
280
}