Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monit configuration for php-fpm

Tags:

php

monit

I'm struggling to find a monit config for php-fpm that works.

This is what I've tried:

### Monitoring php-fpm: the parent process.
check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
  group phpcgi # phpcgi group
  start program = "/etc/init.d/php-fpm start"
  stop program  = "/etc/init.d/php-fpm stop"
  ## Test the UNIX socket. Restart if down.
  if failed unixsocket /var/run/php-fpm.sock then restart
  ## If the restarts attempts fail then alert.
  if 3 restarts within 5 cycles then timeout

But it fails because there is no php-fpm.sock (Centos 6)

like image 300
Adam Jimenez Avatar asked Oct 21 '11 08:10

Adam Jimenez


2 Answers

This is work for me

 check process php5-fpm with pidfile /var/run/php5-fpm.pid
  start program = "/usr/sbin/service php5-fpm start" with timeout 60 seconds
  stop program = "/usr/sbin/service php5-fpm stop"
  if cpu > 60% for 2 cycles then alert
  if cpu > 90% for 5 cycles then restart
  if 3 restarts within 5 cycles then timeout
  group server
like image 154
sanzmalz Avatar answered Sep 19 '22 14:09

sanzmalz


Here is a way of checking php-fpm via a TCP connection (which is more reliable than a simple .pid):

# Empty FastCGI request
if failed port 8101
  # Send FastCGI packet: version 1 (0x01), cmd FCGI_GET_VALUES (0x09)
  # padding 8 bytes (0x08), followed by 8xNULLs padding
  send "\0x01\0x09\0x00\0x00\0x00\0x00\0x08\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00\0x00"
  # Expect FastCGI packet: version 1 (0x01), resp FCGI_GET_VALUES_RESULT (0x0A)
  expect "\0x01\0x0A"
  timeout 5 seconds
then restart

Source: http://richard.wallman.org.uk/2010/03/monitor-a-fastcgi-server-using-monit/

like image 23
Arkadiy Bolotov Avatar answered Sep 18 '22 14:09

Arkadiy Bolotov