Skip to content

PHP-FPM — alert on slow requests over N seconds

You enabled `request_slowlog` in php-fpm.conf — but nobody reads it. Want an endpoint that returns high when > 5 slow requests show up in a minute.

Recipe

bash
#!/usr/bin/env bash
# Counts slowlog entries in the last minute.
LOG="${SLOWLOG:-/var/log/php-fpm/slow.log}"
THRESHOLD="${THRESHOLD:-5}"

[ ! -r "$LOG" ] && { echo "no-log"; exit 1; }
CNT=$(awk -v from="$(date -d '1 min ago' '+%d-%b-%Y %H:%M')" '
  /\[.*\]/ && $0 >= "[" from { c++ } END { print c+0 }
' "$LOG")
[ "$CNT" -ge "$THRESHOLD" ] && echo "high $CNT/min" || echo "ok $CNT/min"

Same thing in Enterno.io

Endpoint + an Enterno HTTP monitor with "ok" keyword every minute = paged within 60s. Correlate with a PageSpeed monitor on a public page to tell PHP-side stalls from upstream-MySQL stalls.

Set up HTTP monitor → ← All recipes

Related recipes

long_query_time = 1, slow_query_log enabled. You need to know when the slow-query rate per minute suddenly jumps (a deploy broke an index, ORM went N+1).