Projet

Général

Profil

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

root / plugins / php / php_fpm_process @ ec4951b7

Historique | Voir | Annoter | Télécharger (3,08 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
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 926c0ee4 Vincent Viallet
# If your php process is listening on TCP 
21 c0e3ed7f minitux
[php_fpm_process]
22
   env.serveraddr 127.0.0.1
23
   env.port 9000
24
   env.path /status 
25
26 926c0ee4 Vincent Viallet
# If your php process is listening on Unix Socket
27
[php_fpm_process]
28
   env.sock /var/run/php5-fpm.sock
29
   env.path /status 
30
31 c0e3ed7f minitux
=head1 MAGIC MARKERS
32
33
  #%# family=auto
34
  #%# capabilities=autoconf
35
36
=head1 VERSION
37
38
  v1.0 
39
40
=head1 AUTHOR
41
42
Minitux 
43
44
=head1 LICENSE
45
46
GNU General Public License, version 3
47
48
=cut
49
50
use FCGI::Client;
51
52
my $ish = 1;
53
my $header = "";
54
my $body = "";
55
my $IDLE = 0;
56
my $ACTIVE = 0;
57
my $TOTAL = 0;
58
59
my $SERVERADDR = $ENV{'serveraddr'} || "127.0.0.1";
60
my $PORT = $ENV{'port'} || "9000";
61
my $PATH = $ENV{'path'} || "/status";
62 926c0ee4 Vincent Viallet
my $UNIX_SOCK = $ENV{'sock'};
63
64
my $sock;
65
66
if ($UNIX_SOCK) {
67
  use IO::Socket::UNIX;
68
  $sock = IO::Socket::UNIX->new(
69
    Peer =>  $UNIX_SOCK,
70
  );
71
  if (!$sock) { 
72
    print "Server maybe down, unabled to connect to $UNIX_SOCK";
73
    exit 2;
74
  }
75
} else {
76
  use IO::Socket::INET;
77
  $sock = IO::Socket::INET->new(
78
    PeerAddr =>  $SERVERADDR,
79
    PeerPort =>  $PORT,
80
  );
81
  if (!$sock) { 
82
    print "Server maybe down, unabled to connect to $SERVERADDR:$PORT";
83
    exit 2;
84
  }
85 c0e3ed7f minitux
}
86
87 926c0ee4 Vincent Viallet
my $client = FCGI::Client::Connection->new( sock => $sock );
88
89
my ( $stdout, $stderr, $appstatus )  = $client->request( 
90
    +{
91
        REQUEST_METHOD => 'GET',
92
        SCRIPT_FILENAME => '',
93
        QUERY_STRING => '',
94
        SCRIPT_NAME    => $PATH,
95
    },
96
    ''
97
  );
98 c0e3ed7f minitux
99
$stdout =~ s/\r//g;
100
101
while($stdout =~ /([^\n]*)\n?/g) {
102 926c0ee4 Vincent Viallet
  if(!$1) {
103
    $ish = 0;
104
    next;
105
  }
106
  if($ish == 1) {
107
    $header .= $1."\n";
108
  } else {
109
    $body .= $1."\n";
110
  }
111 4528900a Calle Kabo
}
112
113
if ( defined $ARGV[0] and $ARGV[0] eq "config" )
114
{
115
 
116
  if($body =~ m/pool:\s+(.*?)\n/) {
117
    $pool = $1;
118
  }
119
120
  print "graph_title php5-fpm status $pool\n";
121
  print "graph_args --base 1000 -l 0\n";
122
  print "graph_vlabel Processes\n";
123
  print "graph_scale yes\n";
124 2ad552cb Mikel Olasagasti Uranga
  print "graph_category php-fpm\n";
125 4528900a Calle Kabo
  print "graph_info This graph shows the php5-fpm process manager status from pool: $pool\n";
126
  print "active.label Active processes\n";
127
  print "active.type GAUGE\n";
128
  print "active.draw AREA\n";
129
  print "active.info The number of active processes\n";
130
  print "idle.label Idle processes\n";
131
  print "idle.type GAUGE\n";
132
  print "idle.draw STACK\n";
133
  print "idle.info The number of idle processes\n";
134
  print "total.label Total processes\n";
135
  print "total.type GAUGE\n";
136
  print "total.draw LINE2\n";
137
  print "total.info The number of idle + active processes\n";
138
  exit 0
139 926c0ee4 Vincent Viallet
} 
140
141
print $body;
142 c0e3ed7f minitux
143
if($body =~ m/idle processes: (.*?)\n/) {
144
        $IDLE = $1;
145 926c0ee4 Vincent Viallet
  print "idle.value ".$IDLE."\n";
146 c0e3ed7f minitux
}
147
if($body =~ m/active processes: (.*?)\n/) {
148
        $ACTIVE = $1;
149 926c0ee4 Vincent Viallet
  print "active.value ".$ACTIVE."\n";
150 c0e3ed7f minitux
}
151
if($body =~ m/total processes: (.*?)\n/) {
152
        $TOTAL = $1;
153 926c0ee4 Vincent Viallet
  print "total.value ".$TOTAL."\n";
154 c0e3ed7f minitux
}