Skip to main content
In this lesson we wrap up with Prometheus’ final core metric type: the Gauge. A Gauge records a single numerical value that can go up and down over time, which makes it ideal for tracking quantities that fluctuate — for example, the number of active requests currently being processed by an application. Key use cases:
  • Current number of in-progress requests
  • Free memory, queue length, or number of running jobs
  • Resource values that both increase and decrease
See Prometheus docs: Gauge metric type. Example: tracking in-progress requests with the Python prometheus_client
  • Important: the order of labelnames must match the order of values passed to .labels(...). In this example we define ['method', 'path'] and call .labels(request.method, request.path).
The Gauge API highlights:
  • inc() — increment the gauge by 1 (or a specified amount)
  • dec() — decrement the gauge by 1 (or a specified amount)
  • set(value) — explicitly set the gauge to value
Ensure every inc() is paired with a corresponding dec() (even when errors occur). In frameworks like Flask, prefer teardown_request, middleware, or a try/finally block around request handling so the gauge is always decremented when a request finishes.
Robust pattern using try/finally inside a handler:
When exposed by your metrics endpoint, the gauge shows the current value per label combination. Example output:
Gauge vs Counter — quick comparison Additional guidance
  • Use a Gauge when you need an up-and-down metric (active jobs, queue length, free resources).
  • For request duration or size distributions, prefer Histogram or Summary.
  • Label cardinality: avoid high-cardinality label values (e.g., raw user IDs or long paths) to prevent memory blowups in the Prometheus server.
Links and references
Never allow unpaired increments. Missing decrements will inflate your gauge and produce misleading monitoring alerts. Implement error paths and teardown hooks to guarantee balanced inc()/dec() calls.

Watch Video