Конфигурация монитора для php-fpm

Я изо всех сил пытаюсь найти конфигурацию monit для php-fpm, которая работает.

Это то, что я пробовал:

### 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

Но это не удается, потому что нет php-fpm.sock (Centos 6)


person Adam Jimenez    schedule 21.10.2011    source источник


Ответы (6)


Я использую директиву ping.path в php-fpm, чтобы проверить, работает ли она...

и настроил его на nginx.conf (я не знаю, ваша ли это настройка)

location /ping {
    access_log     off;
    allow          127.0.0.1;
    deny           all;
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
    include        fastcgi_params;
}
person Marcelo Bittencourt    schedule 26.10.2011

Для всех, кто столкнулся с этой проблемой на Centos 6, сокет php-fpm находится в /var/run/php-fpm/php-fpm.sock.

Следовательно, окончательный конфиг будет таким:

check process php-fpm with pidfile /var/run/php-fpm/php-fpm.pid
  group phpcgi #change accordingly
  start program = "/etc/init.d/php-fpm start"
  stop program  = "/etc/init.d/php-fpm stop"
  if failed unixsocket /var/run/php-fpm/php-fpm.sock then restart
  if 3 restarts within 5 cycles then timeout
person Thom Seddon    schedule 19.06.2012

Вместо:

if failed unixsocket /var/run/php-fpm.sock then restart

вы можете попробовать:

if failed port 9000 type TCP then restart

Не требует редактирования конфига lighttpd/nginx, как в случае location /ping.

Мой /etc/monit/conf.d/php-fpm.conf в Ubuntu выглядит так:

check process php-fpm with pidfile /var/run/php5-fpm.pid
  stop program = "/sbin/start-stop-daemon --stop --pidfile /var/run/php5-fpm.pid"
  start program  = "/sbin/start-stop-daemon --start --pidfile /var/run/php5-fpm.pid --exec /usr/sbin/php5-fpm"
  if failed port 9000 type TCP then restart
person suside    schedule 18.06.2012

Вот способ проверки php-fpm через TCP-соединение (что более надежно, чем простой .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

Источник: http://richard.wallman.org.uk/2010/03/monitor-a-fastcgi-server-using-monit/

person Arkadiy Bolotov    schedule 20.03.2017

это работа для меня

 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
person sanzmalz    schedule 19.03.2018

Это на моем Debian 7 с nginx и php5-fpm;

check process php5-fpm with pidfile /var/run/php5-fpm.pid
group php #change accordingly
start program = "/etc/init.d/php5-fpm start"
stop program  = "/etc/init.d/php5-fpm stop"
if failed unixsocket /tmp/php-fpm.sock then restart
if 3 restarts within 5 cycles then timeout
person Julius Thijssen    schedule 19.04.2013