Projet

Général

Profil

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

root / plugins / php / php_fpm_process @ c5ab6538

Historique | Voir | Annoter | Télécharger (2,55 ko)

1
#!/usr/bin/perl
2
# -*- cperl -*-
3

    
4
=head1 NAME
5

    
6
php_fpm_processes - 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
[php_fpm_process]
21
   env.serveraddr 127.0.0.1
22
   env.port 9000
23
   env.path /status 
24

    
25
=head1 MAGIC MARKERS
26

    
27
  #%# family=auto
28
  #%# capabilities=autoconf
29

    
30
=head1 VERSION
31

    
32
  v1.0 
33

    
34
=head1 AUTHOR
35

    
36
Minitux 
37

    
38
=head1 LICENSE
39

    
40
GNU General Public License, version 3
41

    
42
=cut
43

    
44

    
45
use IO::Socket::INET;
46
use FCGI::Client;
47

    
48
my $ish = 1;
49
my $header = "";
50
my $body = "";
51
my $IDLE = 0;
52
my $ACTIVE = 0;
53
my $TOTAL = 0;
54

    
55
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
56
my $PORT = $ENV{'port'} || "9000";
57
my $PATH = $ENV{'path'} || "/status";
58

    
59
my $sock = IO::Socket::INET->new(
60
        PeerAddr =>  $SERVERADDR,
61
        PeerPort =>  $PORT,
62
);
63

    
64
if (!$sock) { 
65
	print "Server maybe down, unabled to connect to $SERVERADDR:$PORT";
66
	exit 2;
67
}
68

    
69
	my $client = FCGI::Client::Connection->new( sock => $sock );
70
	my ( $stdout, $stderr, $appstatus )  = $client->request( 
71
		+{
72
	            REQUEST_METHOD => 'GET',
73
		    SCRIPT_FILENAME => '',
74
		    QUERY_STRING => '',
75
		    SCRIPT_NAME    => $PATH,
76
		},
77
	        ''
78
	);
79

    
80

    
81
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
82
{
83

    
84
  print "graph_title php5-fpm status $pool";
85
  print "graph_args --base 1000 -l 0";
86
  print "graph_vlabel Processes";
87
  print "graph_scale yes";
88
  print "graph_category php";
89
  print "graph_info This graph shows the php5-fpm process manager status from pool: $pool";
90
  print "active.label Active processes";
91
  print "active.type GAUGE";
92
  print "active.draw AREA";
93
  print "active.info The number of active processes";
94
  print "idle.label Idle processes";
95
  print "idle.type GAUGE";
96
  print "idle.draw STACK";
97
  print "idle.info The number of idle processes";
98
  print "total.label Total processes";
99
  print "total.type GAUGE";
100
  print "total.draw LINE2";
101
  print "total.info The number of idle + active processes";
102
  exit 0
103
}
104

    
105
$stdout =~ s/\r//g;
106

    
107
while($stdout =~ /([^\n]*)\n?/g) {
108
	if(!$1) {
109
		$ish = 0;
110
		next;
111
	}
112
	if($ish == 1) {
113
		$header .= $1."\n";
114
	} else {
115
		$body .= $1."\n";
116
	}
117
}	
118

    
119
if($body =~ m/idle processes: (.*?)\n/) {
120
        $IDLE = $1;
121
	print "idle.value ".$IDLE."\n";
122
}
123
if($body =~ m/active processes: (.*?)\n/) {
124
        $ACTIVE = $1;
125
	print "active.value ".$ACTIVE."\n";
126
}
127
if($body =~ m/total processes: (.*?)\n/) {
128
        $TOTAL = $1;
129
	print "total.value ".$TOTAL."\n";
130
}