threadman 0.1.0
Header-only C++23 managed threads, dynamic pools, futures, and executors
Loading...
Searching...
No Matches
Namespaces | Functions
metrics.hpp File Reference

Cached subsystem metrics for the tm_* Prometheus/OpenMetrics families, mirroring the tm. More...

#include <prom/prom.hpp>
#include <memory>
Include dependency graph for metrics.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  threadman
 
namespace  threadman::metrics
 

Functions

std::shared_ptr< prom::Scope > & threadman::metrics::scope ()
 The shared threadman scope; applies the tm_ prefix to every metric.
 
prom::Counter & threadman::metrics::pool_tasks_submitted ()
 Tasks submitted to a thread pool (all submit variants).
 
prom::Counter & threadman::metrics::pool_tasks_completed ()
 Tasks that ran to completion on a pool worker.
 
prom::Counter & threadman::metrics::pool_tasks_failed ()
 Tasks whose body threw an exception.
 
prom::Counter & threadman::metrics::pool_tasks_cancelled ()
 Tasks cancelled before running (drained by shutdown_now).
 
prom::Counter & threadman::metrics::pool_queue_rejected ()
 Submissions rejected because a bounded queue was full.
 
prom::Counter & threadman::metrics::pool_submit_rejected ()
 Submissions rejected because the pool was shutting down or terminated.
 
prom::Counter & threadman::metrics::pool_scale_ups ()
 Non-core workers spawned by a scale-up decision.
 
prom::Counter & threadman::metrics::pool_scale_downs ()
 Non-core workers retired after idling out.
 
prom::Gauge & threadman::metrics::pool_queue_depth ()
 Tasks currently waiting in a pool's queue (set from the summary tick).
 
prom::Gauge & threadman::metrics::pool_workers ()
 Live workers in a pool (set from the summary tick).
 
prom::Gauge & threadman::metrics::pool_workers_active ()
 Workers currently executing a task (set from the summary tick).
 
prom::Gauge & threadman::metrics::pool_workers_idle ()
 Workers currently idle on the queue (set from the summary tick).
 
prom::Histogram & threadman::metrics::pool_task_execution_seconds ()
 Wall-clock seconds a task body spent executing.
 
prom::Histogram & threadman::metrics::pool_task_queue_wait_seconds ()
 Seconds a task waited in the queue before a worker picked it up.
 
prom::Counter & threadman::metrics::threads_created ()
 ManagedThread bodies that entered (started running).
 
prom::Counter & threadman::metrics::threads_completed ()
 ManagedThread bodies that returned normally.
 
prom::Counter & threadman::metrics::threads_failed ()
 ManagedThread bodies that exited by throwing.
 
prom::Gauge & threadman::metrics::threads_live ()
 ManagedThread bodies currently running (inc on enter, dec on exit).
 
prom::Counter & threadman::metrics::manager_threads_registered ()
 Thread control blocks registered with the manager.
 
prom::Counter & threadman::metrics::manager_summaries_published ()
 Periodic ManagerSummary payloads published to listeners.
 
prom::Gauge & threadman::metrics::manager_pools_live ()
 Pools currently registered with the manager (set from the summary tick).
 
prom::Counter & threadman::metrics::tasks_stuck_detected ()
 Distinct tasks newly detected as stuck (running past the threshold).
 
prom::Gauge & threadman::metrics::tasks_stuck_current ()
 Tasks currently flagged as stuck (set from the housekeeper tick).
 
prom::Counter & threadman::metrics::futures_created ()
 Promise/Future pairs created.
 
prom::Counter & threadman::metrics::futures_satisfied_value ()
 Futures satisfied with a value.
 
prom::Counter & threadman::metrics::futures_satisfied_exception ()
 Futures satisfied with an exception.
 
prom::Counter & threadman::metrics::future_continuations_registered ()
 .then/.on_error continuations registered against a future.
 
prom::Counter & threadman::metrics::future_continuations_dispatched ()
 Continuations dispatched through an executor.
 
void threadman::metrics::warm_up ()
 Eagerly construct the scope and every metric handle (and, transitively, prom's process-wide adapter cell / NullAdapter).
 

Detailed Description

Cached subsystem metrics for the tm_* Prometheus/OpenMetrics families, mirroring the tm.

* logging channels in <threadman/log.hpp>.

Each accessor returns a long-lived metric handle created on first call via a shared prom::Scope named "threadman" (metric prefix "tm_"). The handle is cached in a static-local, so subsequent calls are a no-op load. Per-pool series are selected at the call site with .labels(prom::Labels{{"pool", opts_.name}}); the only dynamic labels are pool (operator-bounded pool name) and pool_id (numeric) — never task ids, thread ids, or exception text, which would be unbounded cardinality.

Metrics are always-on and safe by default: until a host application installs a backend via prom::Registry::global()->set_adapter(...), every metric op is a noexcept no-op through prom's NullAdapter — the same safety profile as a logger with no sinks. This header never installs an adapter; it just declares the scope and its metrics.

Histograms observe seconds (convert nanosecond durations via /1e9).