Skip to content

Tomcat — alert when HTTP connector approaches maxThreads

Under load the Tomcat connector pegs at `maxThreads=200` — new requests queue, p99 latency climbs. JMX has the metric but nobody is watching.

Recipe

bash
#!/usr/bin/env bash
# Tomcat 9+ Manager / JMX servlet returns currentThreadsBusy.
HOST="${TOMCAT:-http://localhost:8080}"
USER_PASS="${TOMCAT_AUTH:-admin:admin}"
PORT="${PORT:-8080}"
THRESHOLD_PCT="${THRESHOLD_PCT:-80}"

XML=$(curl -sS -u "$USER_PASS" "$HOST/manager/status?XML=true")
BUSY=$(echo "$XML" | grep -oE "currentThreadsBusy=\"[0-9]+\"" | head -1 | grep -oE '[0-9]+')
MAX=$(echo "$XML"  | grep -oE "maxThreads=\"[0-9]+\""        | head -1 | grep -oE '[0-9]+')

[ -z "$BUSY" ] || [ -z "$MAX" ] && { echo "no-data"; exit 1; }
PCT=$((BUSY * 100 / MAX))
[ "$PCT" -ge "$THRESHOLD_PCT" ] && echo "high ${PCT}% (${BUSY}/${MAX})" || echo "ok ${PCT}%"

Same thing in Enterno.io

Endpoint + Enterno HTTP monitor with "ok" keyword every minute. Pro+ stores history — surfaces patterns like "saturates at 14:00 daily from a cron job".

Set up HTTP monitor → ← All recipes

Related recipes

Spring app is sluggish — long GC pauses (>500ms) every few minutes. Heap size was fine but the new-gen ratio is misconfigured. Want an endpoint with p99 pause.