-
Notifications
You must be signed in to change notification settings - Fork 45
/
phpfpm_connections
107 lines (80 loc) · 2.13 KB
/
phpfpm_connections
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl
# -*- perl -*-
=encoding utf8
=head1 NAME
phpfpm_connections - Munin plugin to monitor the number of accepted connections to PHP-FPM.
=head1 CONFIGURATION
For this plugin, you will need to enable the status feature
included in versions 5.3.2+ of PHP-FPM. The directive can be
found in the php-fpm.conf file:
pm.status_path = /status
You might need to specify connection parameters in the plugin
configuration to override the defaults. These are the defaults:
[phpfpm_*]
env.url http://127.0.0.1/status
env.ports 80
=head1 PARAMETERS:
config (required)
autoconf (optional - used by munin-config)
=over
=head1 LICENSE
Copyright TJ Stein 2010 http://constantshift.com
=head1 MAGICK MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
my $ret = undef;
if (! eval "require LWP::UserAgent;")
{
$ret = "LWP::UserAgent not found";
}
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/status";
my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80);
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" )
{
if ($ret)
{
print "no ($ret)\n";
exit 1;
}
my $ua = LWP::UserAgent->new(timeout => 30);
my @badports;
foreach my $port (@PORTS) {
my $url = sprintf $URL, $port;
my $response = $ua->request(HTTP::Request->new('GET',$url));
push @badports, $port unless $response->is_success and $response->content =~ /^accepted conn:/im;
}
if (@badports) {
print "no (phpfpm-status)\n";
exit 1;
} else {
print "yes\n";
exit 0;
}
}
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
{
print('graph_title PHP-FPM Accepted Connections
graph_args --base 1024 -l 0
graph_vlabel Connections
graph_category PHP
graph_info Plugin created by TJ Stein
accepted.label Accepted
accepted.draw AREA
accepted.type DERIVE
accepted.min 0
');
exit 0;
}
foreach my $port (@PORTS)
{
my $ua = LWP::UserAgent->new(timeout => 30);
my $url = sprintf $URL, $port;
my $response = $ua->request(HTTP::Request->new('GET',$url));
if ($response->content =~ /accepted conn:\s+([0-9\.]+)/im) {
print "accepted.value $1\n";
} else {
print "accepted.value U\n";
}
}
# vim:syntax=perl