How to scrape and query metrics with Prometheus#

This guide shows you how to scrape the @@metrics endpoint with Prometheus and query the result with PromQL.

It assumes the observability filter is wired. See How to install plone.observability.

Add a scrape job#

Point Prometheus at the main Zope port with the @@metrics path.

scrape_configs:
  - job_name: plone
    static_configs:
      - targets: ["plone-host:8080"]
    metrics_path: /@@metrics

If you restrict access with PLONE_OBSERVABILITY_METRICS_ALLOWLIST, add the Prometheus server’s CIDR to the allowlist. See Configuration.

Query the metrics#

Total requests across all instances:

sum(plone_requests_total{job="plone"})

Request rate per instance over a five-minute window:

rate(plone_requests_total{job="plone"}[5m])

Approximate median request duration from the histogram:

histogram_quantile(0.5,
  sum(rate(plone_request_duration_seconds_bucket[5m])) by (le, instance)
)

Memory per instance in megabytes:

plone_process_rss_bytes{job="plone"} / 1024 / 1024

Read global metrics from one instance#

Global metrics report the same value on every instance that shares the ZODB. Summing them double-counts. Query a single instance instead:

plone_zodb_object_count{instance="plone-0:8080", scope="global"}

Watch ZODB contention#

Overall conflict rate:

rate(plone_zodb_conflicts_total[5m])

Conflicts that gave up after the final retry, the ones users actually felt:

rate(plone_zodb_conflicts_total{retry="false"}[5m])

A loads-per-request smell test that catches views waking up too many objects:

rate(plone_zodb_loads_total[5m]) / rate(plone_requests_total[5m])

Find where memory grows#

Growth of the anonymous memory, the part that leaks, over six hours:

delta(plone_process_rss_anon_bytes{job="plone"}[6h])

Growth of live Python objects over the same window:

delta(plone_python_allocated_blocks{job="plone"}[6h])

Interned strings that keep growing point at code that is compiled again and again:

deriv(plone_python_interned_strings{job="plone"}[1h]) > 0

Time spent in garbage collection, as a share of wall-clock time:

rate(plone_gc_pause_seconds_sum{job="plone"}[5m])

With PLONE_OBSERVABILITY_REQUEST_RSS=1, the rate of requests that grew the process by more than 16 MiB:

rate(plone_request_rss_growth_bytes_count[5m])
  - ignoring(le) rate(plone_request_rss_growth_bytes_bucket{le="16777216"}[5m])

Released ZODB connections that stayed in memory for a whole hour, a sign of connections pinned by a leftover reference:

min_over_time(plone_zodb_connections_alive{database="main"}[1h])
  - max_over_time(plone_zodb_connections{database="main"}[1h]) > 0

With PLONE_OBSERVABILITY_MALLINFO=1, the share of the glibc heap that is free but not returned to the system:

plone_malloc_free_bytes / (plone_malloc_free_bytes + plone_malloc_inuse_bytes)

With jemalloc preloaded, the share of its active pages that holds no allocation:

1 - plone_jemalloc_allocated_bytes / plone_jemalloc_active_bytes

See also

  • Metrics for the full metric list and the scope label.

  • About metrics and cardinality for what global versus instance scope means, why the conflict and load counters exist, and how to read the memory metrics.