Prometheus Metrics

OxPHP exposes Prometheus-compatible metrics in text exposition format at GET /metrics on the internal server. They cover request throughput, response times, connection state, worker pool health, static file caching, compression, worker mode and the profiler.

Enabling metrics

Set INTERNAL_ADDR to start the internal server:

bash
INTERNAL_ADDR=127.0.0.1:9090

Then scrape from Prometheus or any compatible collector:

bash
curl http://localhost:9090/metrics

Server metrics

Metric Type Description
oxphp_uptime_seconds gauge Seconds since the server process started
oxphp_requests_total counter Total HTTP requests received on the main port

Request metrics

Metric Type Description
oxphp_requests_by_method_total counter Requests by HTTP method. Label: method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT, QUERY, OTHER)
oxphp_responses_by_status_total counter Responses by status class. Label: status (1xx, 2xx, 3xx, 4xx, 5xx)
oxphp_request_bytes_total counter Total request body bytes received
oxphp_response_bytes_total counter Total response body bytes sent
oxphp_request_cancelled_total counter Cancelled requests by reason. Label: reason (client_abort, timeout, shutdown). Always emitted

oxphp_request_cancelled_total counts each request the server dispatches (not only the ones that reach PHP) once, when that request is answered. So client_abort covers a client that hung up while its request was still queued (the common case) and one that hung up while its handler ran. A client that hangs up after the response has started going out is not counted.

Note

Only methods and status classes with at least one recorded event are emitted. Zero-count labels are omitted.

Request duration histogram

Metric Type Description
oxphp_request_duration_us histogram End-to-end request duration in microseconds for all requests (static files and PHP)

Bucket boundaries (microseconds): 100, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000, 250000, 500000, 1000000, +Inf.

Use this histogram to track overall latency, find slow endpoints, and measure tail latency percentiles.

Connection metrics

Metric Type Description
oxphp_active_connections gauge Currently open TCP connections on the main port
oxphp_accept_stalled gauge 1 while the accept loop waits for a free MAX_CONNECTIONS permit. The kernel still accepts connections, but nothing new is served, so to clients the server has stopped answering
oxphp_accept_stalls_total counter Connections that had to wait for a MAX_CONNECTIONS permit after being accepted. It moves even when a stall starts and ends between two scrapes, which the gauge would miss
oxphp_pending_requests gauge PHP requests accepted but not yet answered: waiting for a queue slot, queued, or executing. Static files, 404s and denied paths never appear here
oxphp_dropped_requests_total counter Requests where the PHP worker failed after accepting the request
oxphp_admission_refused_total counter Requests answered without reaching a worker. Label: reason, listed under Refusal reasons
oxphp_admission_wait_wasted_total counter Requests that waited out their whole wait budget while the pool started no request at all; a subset of reason="wait_timeout". Counts only while the budget is at its ceiling (how to read it)
oxphp_queue_depth gauge Requests in the worker queue that no worker has picked up yet. Requests already answered on their deadline (529, or 499 where the client had gone) stay in it until a pickup, and no metric counts them on their own
oxphp_queue_capacity gauge Queue slots in total: QUEUE_CAPACITY, the bound oxphp_queue_depth is read against
oxphp_admission_slots_available gauge Admission permits nobody holds: the room a new arrival can take without waiting. A request takes one before it enters the queue and gives it back when a worker picks it up
oxphp_admission_wait_budget_us gauge How long a request arriving now may wait for a worker, in microseconds (the unit of oxphp_queue_wait_us). QUEUE_WAIT_TIMEOUT_MS is its ceiling, and the server lowers it while clients leave before they are served (how)
oxphp_admission_wait_budget_ceiling_us gauge QUEUE_WAIT_TIMEOUT_MS in microseconds, constant for the life of the process. Alert on the budget's ratio to it, not on a number copied from the configuration
oxphp_abandoned_work_total counter Requests a worker took off the queue whose client had already gone; the wait budget is adjusted against this count. Requests refused on their deadline are not counted (how to read it)
oxphp_pool_stalled gauge 1 while requests wait for idle workers that get nothing done: a pool that has stopped taking work off its queue. Worker mode only (details)

Alert on oxphp_accept_stalled == 1 directly, and on rate(oxphp_accept_stalls_total[5m]) > 0 for stalls too short for a scrape to catch. Either means the MAX_CONNECTIONS budget runs out: raise it or shrink the PHP backlog (QUEUE_CAPACITY + QUEUE_MAX_WAITING), as Keeping headroom for the accept loop explains.

oxphp_queue_depth and the two wait-budget gauges are present only for the SAPI executor, the only one with a queue. Both budget gauges read 0 in fail-fast mode (QUEUE_WAIT_TIMEOUT_MS=0), where there is no wait to adjust. During a graceful drain nothing is admitted, whatever oxphp_admission_slots_available reads.

oxphp_abandoned_work_total sees only clients that close their connection: one that stops waiting without closing looks like any other completion.

oxphp_pool_stalled is set once the state has held for a minute, long enough that a worker reloading the application after a recycle does not raise it. A worker finishing a request clears it, as does a minute in which the pool has not looked wedged. Alert on oxphp_pool_stalled == 1; the readiness probe answers 503 on the same state. Outside worker mode the series is absent, not 0.

How to read these gauges together during an incident, and what the server logs while it sheds requests or the pool stalls, is in Diagnosing Overload.

Refusal reasons

The reason label of oxphp_admission_refused_total takes these values:

Reason Answer Meaning What to change
wait_timeout 529 Waited out its whole wait budget: QUEUE_WAIT_TIMEOUT_MS, or less where the server has shortened it Give the pool more headroom. Read oxphp_admission_wait_wasted_total first: where it climbs, shorten the wait instead
waiting_full 529 QUEUE_MAX_WAITING requests were already waiting Raise QUEUE_MAX_WAITING or MAX_CONNECTIONS
waiting_bytes 529 The bodies already waiting fill QUEUE_MAX_WAITING_BYTES, so this request's body had nowhere to sit Raise QUEUE_MAX_WAITING_BYTES, or lower how much a client may upload
queue_full 529 The queue was full and waiting is off (QUEUE_WAIT_TIMEOUT_MS=0) See QUEUE_WAIT_TIMEOUT_MS=0 is not a shorter wait
shutting_down 503 The drain deadline passed while the request was still waiting for admission —
pool_unavailable 500 No worker thread is left to hand the request to: the pool is gone, not busy —

Only the first four are overload. Alert on them by name, since the series as a whole also moves on a restart.

A request whose client had already gone when its budget ran out is not counted here. It is answered 499 and counted in oxphp_request_cancelled_total{reason="client_abort"}, so this series stays a statement about the pool. Refused requests are not recorded in oxphp_queue_wait_us.

Worker pool metrics

Metric Type Description
oxphp_workers_current gauge Current number of PHP worker threads
oxphp_workers_min gauge Minimum worker count (equals current count in static mode)
oxphp_workers_max gauge Maximum worker count (equals current count in static mode)
oxphp_workers_idle gauge Worker threads with no request in flight: workers_current - busy_workers
oxphp_busy_workers gauge Worker threads executing at least one request; never above oxphp_workers_current. It counts threads, not requests: in worker mode a thread multiplexing many request fibers counts once
oxphp_workers_spawned_total counter Total workers spawned since startup (includes initial workers)
oxphp_workers_retired_total counter Total workers retired due to idle timeout (dynamic mode only)

Worker supervisor metrics

The worker supervisor emits these per worker. Each series carries a worker_id label (the slot index), and appears once the supervisor tracks per-worker state.

Metric Type Description
oxphp_worker_request_age_seconds gauge Age of the in-flight request on each worker, in seconds. Label: worker_id
oxphp_worker_long_running_total counter Supervisor scans that saw a request older than the stuck threshold (60 seconds, fixed). Label: worker_id
oxphp_worker_stuck_total counter Requests classified as stuck, per worker. Labels: worker_id, kind (io, c_call, cpu)

oxphp_worker_stuck_total is reporting only: a request classified as stuck is not cancelled, and its worker is not recycled. Nothing in the server acts on it, so alert on this series.

Queue wait histogram

Metric Type Description
oxphp_queue_wait_us histogram Time a request waits in the queue before a worker picks it up, in microseconds

Bucket boundaries (microseconds): 50, 100, 250, 500, 1000, 2500, 5000, 10000, 50000, 100000, 250000, 500000, 1000000, +Inf.

This is the time spent waiting, for admission and then in the queue, until a worker takes the request. It answers "how long before a worker picked this up", not "how long did the request take". Everything after that moment counts towards oxphp_request_duration_us: the worker preparing the request, the script (up to the response head, for a streamed response), and handing the response back to the server's I/O threads. On a cheap script, that handoff can take several times as long as the script itself.

Only a request a worker took off the queue within its budget is recorded. A refusal (529, 503 or 500) is counted in oxphp_admission_refused_total, and a 499 for a client that left first in oxphp_request_cancelled_total{reason="client_abort"}.

A high queue wait is not by itself a shortage of workers: every reading includes the time a worker thread takes to reach a request handed to it, even on an unloaded server. Before raising PHP_WORKERS, check that requests find every worker busy and that the machine has cores to spare (the server's I/O threads, other processes and a container CPU quota compete with the workers).

oxphp_busy_workers against oxphp_workers_current answers the first question only in part. It is read at scrape time, so a burst that fills the pool between scrapes shows here and not there. In worker mode a thread counts as busy while it carries any request, even while that request is suspended. A suspended request does not stop the thread from taking more, unless the thread is holding new requests back behind a paused request with an open session or, with RUNTIME_HOOKS on, behind its first request.

The buckets reach one second, the default QUEUE_WAIT_TIMEOUT_MS, so a request that spent most of its budget waiting is still measured. Nothing that is served waits longer than the budget, so raising QUEUE_WAIT_TIMEOUT_MS is the one setting that puts waits into +Inf.

Rate limiting metrics

Metric Type Description
oxphp_rate_limited_total counter Requests rejected by the rate limiter (returned 429)
oxphp_php_deny_total counter Requests blocked by PHP_DENY_PATHS (.php execution denied). See PHP Execution Deny-List
oxphp_path_deny_total counter Requests denied by a .oxphpdeny rule. A request that PHP_DENY_PATHS denies as well is counted here only. See Path Deny Rules

Static file cache metrics

Metric Type Description
oxphp_static_cache_hits_total counter Static file requests served from the in-memory cache
oxphp_static_cache_misses_total counter Static file requests that required a disk read

Compression metrics

Metric Type Description
oxphp_compressed_responses_total counter Responses sent under a content coding (Brotli, zstd, or gzip)
oxphp_compression_bytes_saved_total counter Total bytes saved by compression (original size minus compressed size)

Worker mode metrics

These metrics are only emitted when worker mode is active (WORKER_MODE_ENABLED=true).

Global counters

Metric Type Description
oxphp_worker_mode_enabled gauge Always 1 when worker mode is active
oxphp_worker_requests_handled_total counter Total requests processed by persistent workers
oxphp_worker_recycles_total counter Worker recycles: a worker's loop ended for one of the reasons below. A dynamic pool retiring an idle worker is counted in oxphp_workers_retired_total instead
oxphp_worker_recycles_by_reason_total counter Recycles by reason. Label: reason (scheduled, max_memory, error)
oxphp_worker_soft_resets_total counter Total soft resets performed between requests

Per-worker gauges

Metric Type Description
oxphp_worker_memory_bytes gauge PHP heap held by each worker at the end of its last request: what memory_get_usage() returns in a handler, and what WORKER_MAX_MEMORY_MIB is measured against. Label: worker
oxphp_worker_uptime_seconds gauge Seconds since each worker was spawned. Label: worker
oxphp_worker_requests_count gauge Requests handled by each worker instance. Label: worker
oxphp_worker_request_fibers_active gauge Request fibers the worker carries now: 0 idle, 1 serving one request, higher where suspended requests are multiplexed on the thread. A worker admits at most 256 (reading it). Label: worker

The worker label is the slot index ("0", "1"). A recycled worker reuses its predecessor's slot, and its last values, until it finishes a request of its own.

oxphp_worker_memory_bytes is read as the response is sent, after the finished request has released its superglobals, and the memory ceiling is checked after that. Other requests multiplexed on the worker can allocate or free memory in between, so the two figures can differ: set an alert below the ceiling, not at it. A worker that has never served a request reads 0.

Reading the fiber count

oxphp_worker_request_fibers_active is refreshed on every turn of the worker's loop, not when a request completes. So it does not freeze at its last healthy value on a worker that has stopped completing requests.

A worker at 256 fibers has stopped taking work off the queue while it keeps running. Read it with oxphp_busy_workers: 256 fibers on a worker the pool counts as idle are fibers that outlived their requests (those were answered) and were never reclaimed, while 256 on a busy worker is that many requests in flight.

Worker request duration histogram

Metric Type Description
oxphp_worker_request_duration_us histogram PHP handler execution time per request in microseconds (worker mode only)

Bucket boundaries (microseconds): 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, +Inf.

This histogram measures time spent inside the PHP handler callback, excluding queue wait time. Use it to find slow handlers and track tail latency in worker mode.

Async pool metrics

These metrics require a non-zero ASYNC_WORKERS. The counters appear after the first task is dispatched or rejected, the two in-flight gauges once the pool has wired its in-flight counter, and oxphp_async_output_discarded_bytes_total after output is first discarded.

Metric Type Description
oxphp_async_tasks_dispatched_total counter Total async tasks dispatched to the background pool
oxphp_async_tasks_completed_total counter Async tasks that completed successfully
oxphp_async_tasks_failed_total counter Async tasks that threw an exception
oxphp_async_tasks_cancelled_total counter Async tasks that were cancelled
oxphp_async_tasks_rejected_total counter Async tasks rejected at dispatch, because the pool queue was full or the in-flight cap (ASYNC_MAX_FIBERS × ASYNC_WORKERS) was reached
oxphp_async_tasks_stranded_total counter Tasks left running past an await_race / await_any timeout. Each can delay the end of its request by up to 5 seconds, or until it stops when its code is not in OPcache shared memory (details)
oxphp_async_tasks_in_flight gauge Async tasks currently queued or running
oxphp_async_tasks_in_flight_limit gauge Maximum concurrent async tasks (ASYNC_MAX_FIBERS × ASYNC_WORKERS)
oxphp_async_output_discarded_bytes_total counter Bytes of async-task output discarded at worker idle (an echo in an async task has no client to receive it)

OpenTelemetry export metrics

These metrics require OTEL_ENABLED=true. They count the batches of spans OxPHP sends to the OTLP collector: the request spans, plus the APM spans when the APM plugin is on.

Metric Type Description
oxphp_otel_export_failures_total counter Span exports that failed, after the retry where one was made. Their spans are not sent again
oxphp_otel_export_failed_spans_total counter Spans carried by those failed exports
oxphp_otel_export_retries_total counter Exports retried once because the first attempt failed fast, without an answer from the collector

An export is retried once when its first attempt fails without an answer within half of OTEL_EXPORTER_OTLP_TIMEOUT or one second, whichever is shorter: the connection was reset, closed, or could not be made. The usual cause is a load balancer or NAT that dropped the idle connection between exports. An error status from the collector, such as a rejected API key or throttling, is not retried: the OTLP specification forbids retrying most of them. An attempt that runs into the export timeout is not retried either, so a slow collector is never sent the same batch twice. A retry that delivers the batch is counted only in oxphp_otel_export_retries_total.

A retry can duplicate spans: when the collector did receive the first attempt before the connection broke, it gets those spans twice. For the same reason, an export counted as failed may still have reached the collector.

Spans the tracer drops before export because its queue is full (OTEL_BSP_MAX_QUEUE_SIZE, 2048 spans by default) are not counted here.

Profiler metrics

These metrics require PROFILER_ENABLED=true. They replace the GET /__profiler/stats endpoint, which 0.16.0 removes.

Metric Type Description
oxphp_profiler_runs_total counter Profile runs captured, by what started them. Label: source (header, sample, sdk)
oxphp_profiler_spans_collected_total counter Spans captured across all runs
oxphp_profiler_bytes_written_total counter Profile bytes written to disk. Label: format (xhprof, collapsed)
oxphp_profiler_disk_drops_total counter Profiles not written to disk, because PROFILER_DISK_MAX_PER_SEC was exceeded or the write failed
oxphp_profiler_http_push_failures_total counter Pushes to PROFILER_EXPORT_URL that still failed after all retries
oxphp_profiler_truncated_total counter Runs whose span tree reached PROFILER_MAX_SPANS
oxphp_profiler_in_memory_runs gauge Runs currently held in memory

source="header" counts runs the X-OxPHP-Profile header started, sample runs picked by PROFILER_SAMPLE_RATE, and sdk runs a request started for itself with OxPHP\Profile\start(). The label values format="speedscope", format="pprof", source="cookie" and source="query" no longer appear, so a dashboard or alert selecting them goes empty. Alerts for these series are in the profiler reference.

Grafana dashboard tips

The following PromQL queries are useful for building dashboards:

Request rate (requests per second):

text
rate(oxphp_requests_total[5m])

Average response time (milliseconds):

text
rate(oxphp_request_duration_us_sum[5m]) / rate(oxphp_requests_total[5m]) / 1000

p99 request duration (milliseconds):

text
histogram_quantile(0.99, rate(oxphp_request_duration_us_bucket[5m])) / 1000

Error rate (5xx responses as a percentage):

text
rate(oxphp_responses_by_status_total{status="5xx"}[5m]) / rate(oxphp_requests_total[5m]) * 100

Worker pool utilization:

text
oxphp_busy_workers / oxphp_workers_current

This is a fraction between 0 and 1. Sustained values at 1 mean every worker is occupied and further arrivals are queueing. Pair it with rate(oxphp_admission_refused_total{reason=~"queue_full|wait_timeout|waiting_full|waiting_bytes"}[5m]) to see whether that backlog is turning into refusals, and with oxphp_pending_requests to see how deep it is.

Dropped requests (per second):

text
rate(oxphp_dropped_requests_total[5m])

p99 queue wait (microseconds):

text
histogram_quantile(0.99, rate(oxphp_queue_wait_us_bucket[5m]))

Static file cache hit rate:

text
rate(oxphp_static_cache_hits_total[5m]) / (rate(oxphp_static_cache_hits_total[5m]) + rate(oxphp_static_cache_misses_total[5m]))

Bytes saved by compression per second:

text
rate(oxphp_compression_bytes_saved_total[5m])

Worker mode p99 latency (microseconds):

text
histogram_quantile(0.99, rate(oxphp_worker_request_duration_us_bucket[5m]))

Wait budget driven below its ceiling (fraction):

text
oxphp_admission_wait_budget_us / oxphp_admission_wait_budget_ceiling_us

1 is normal; anything lower means the server is shortening waits under overload. Alert on the ratio, not on a number copied from QUEUE_WAIT_TIMEOUT_MS.

Accept loop stalls (alert when non-zero):

text
rate(oxphp_accept_stalls_total[5m])

Worker recycle rate (per minute):

text
rate(oxphp_worker_recycles_total[5m]) * 60

Average worker memory usage:

text
avg(oxphp_worker_memory_bytes)

Prometheus scrape config

Add a scrape job to your prometheus.yml:

prometheus.yml
scrape_configs: - job_name: "oxphp" scrape_interval: 15s static_configs: - targets: ["oxphp:9090"]

For Kubernetes service discovery:

prometheus.yml
scrape_configs: - job_name: "oxphp" kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] regex: oxphp action: keep - source_labels: [__meta_kubernetes_pod_ip] target_label: __address__ replacement: "$1:9090"

Prompts for your agent

These prompts assume an agent with the OxPHP documentation MCP server connected. The agent reads the pages it needs itself.

prompt
Get Prometheus scraping my OxPHP service. Read the `operations/metrics` page through the OxPHP documentation MCP server. Add the scrape config and whatever my Compose or Kubernetes files need for the metrics endpoint to be reachable, using the service names already in this repository.
prompt
Build me a starting Grafana dashboard for OxPHP. Read the `operations/metrics` page through the OxPHP documentation MCP server. Pick the metrics that actually tell me whether my application is healthy, and explain what each panel would be telling me when it moves.

See also

Found a mistake? Report it