9

我正在努力寻找适用于 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)

4

6 回答 6

14

对于在 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
于 2012-06-19T10:47:35.917 回答
4

代替:

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

你可以试试:

if failed port 9000 type TCP then restart

它不需要像这种location /ping情况那样编辑 lighttpd/nginx 配置。

/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
于 2012-06-18T08:23:43.403 回答
3

我正在使用 php-fpm 中的 ping.path 指令来检查它是否工作......

并在 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;
}
于 2011-10-26T22:53:10.623 回答
1

这是一种通过 TCP 连接检查 php-fpm 的方法(比简单的 .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/

于 2017-03-20T18:05:28.463 回答
1

这对我来说是工作

 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
于 2018-03-19T04:50:06.907 回答
0

这是在我运行 nginx 和 php5-fpm 的 debian 7 上;

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
于 2013-04-19T09:44:44.757 回答