23#include <prom/prom.hpp>
30inline std::shared_ptr<prom::Scope>&
scope() {
31 static std::shared_ptr<prom::Scope> sc =
32 prom::scope(
"threadman", prom::ScopeConfig{.prefix =
"tm_"});
42 static prom::Counter m =
43 scope()->counter({.name =
"pool_tasks_submitted_total",
44 .help =
"Tasks submitted to a thread pool (all submit variants)."});
50 static prom::Counter m =
51 scope()->counter({.name =
"pool_tasks_completed_total",
52 .help =
"Tasks that ran to completion on a pool worker."});
58 static prom::Counter m =
scope()->counter(
59 {.name =
"pool_tasks_failed_total", .help =
"Tasks whose body threw an exception."});
65 static prom::Counter m =
66 scope()->counter({.name =
"pool_tasks_cancelled_total",
67 .help =
"Tasks cancelled before running (drained by shutdown_now)."});
73 static prom::Counter m =
74 scope()->counter({.name =
"pool_queue_rejected_total",
75 .help =
"Submissions rejected because a bounded queue was full."});
81 static prom::Counter m =
scope()->counter(
82 {.name =
"pool_submit_rejected_total",
83 .help =
"Submissions rejected because the pool was shutting down or terminated."});
89 static prom::Counter m =
scope()->counter(
90 {.name =
"pool_scale_ups_total", .help =
"Non-core workers spawned by a scale-up."});
96 static prom::Counter m =
scope()->counter(
97 {.name =
"pool_scale_downs_total", .help =
"Non-core workers retired after idling out."});
103 static prom::Gauge m =
scope()->gauge(
104 {.name =
"pool_queue_depth", .help =
"Tasks currently waiting in a pool's queue."});
110 static prom::Gauge m =
111 scope()->gauge({.name =
"pool_workers", .help =
"Live workers in a pool."});
117 static prom::Gauge m =
scope()->gauge(
118 {.name =
"pool_workers_active", .help =
"Workers currently executing a task."});
124 static prom::Gauge m =
scope()->gauge(
125 {.name =
"pool_workers_idle", .help =
"Workers currently idle on the queue."});
131 static prom::Histogram m =
scope()->histogram(
132 {.name =
"pool_task_execution_seconds",
133 .help =
"Wall-clock seconds a task body spent executing.",
134 .buckets = {0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0}});
140 static prom::Histogram m =
scope()->histogram(
141 {.name =
"pool_task_queue_wait_seconds",
142 .help =
"Seconds a task waited in the queue before a worker picked it up.",
143 .buckets = {0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0}});
153 static prom::Counter m =
scope()->counter(
154 {.name =
"threads_created_total", .help =
"ManagedThread bodies that started running."});
160 static prom::Counter m =
161 scope()->counter({.name =
"threads_completed_total",
162 .help =
"ManagedThread bodies that returned normally."});
168 static prom::Counter m =
scope()->counter(
169 {.name =
"threads_failed_total", .help =
"ManagedThread bodies that exited by throwing."});
175 static prom::Gauge m =
176 scope()->gauge({.name =
"threads_live", .help =
"ManagedThread bodies currently running."});
186 static prom::Counter m =
187 scope()->counter({.name =
"manager_threads_registered_total",
188 .help =
"Thread control blocks registered with the manager."});
194 static prom::Counter m =
195 scope()->counter({.name =
"manager_summaries_published_total",
196 .help =
"Periodic ManagerSummary payloads published to listeners."});
202 static prom::Gauge m =
scope()->gauge(
203 {.name =
"manager_pools_live", .help =
"Pools currently registered with the manager."});
213 static prom::Counter m =
scope()->counter(
214 {.name =
"tasks_stuck_detected_total",
215 .help =
"Distinct tasks newly detected as stuck (running past the threshold)."});
221 static prom::Gauge m =
scope()->gauge(
222 {.name =
"tasks_stuck_current", .help =
"Tasks currently flagged as stuck."});
232 static prom::Counter m =
scope()->counter(
233 {.name =
"futures_created_total", .help =
"Promise/Future pairs created."});
239 static prom::Counter m =
scope()->counter(
240 {.name =
"futures_satisfied_value_total", .help =
"Futures satisfied with a value."});
246 static prom::Counter m =
scope()->counter({.name =
"futures_satisfied_exception_total",
247 .help =
"Futures satisfied with an exception."});
253 static prom::Counter m =
scope()->counter(
254 {.name =
"future_continuations_registered_total",
255 .help =
"Continuations registered against a future (.then / .on_error)."});
261 static prom::Counter m =
262 scope()->counter({.name =
"future_continuations_dispatched_total",
263 .help =
"Continuations dispatched through an executor."});
285 const prom::Labels none{};
286 auto bind_counter = [&](
const prom::Counter& c) { (void)c.labels(none); };
287 auto bind_gauge = [&](
const prom::Gauge& g) { (void)g.labels(none); };
288 auto bind_histogram = [&](
const prom::Histogram& h) { (void)h.labels(none); };
Definition metrics.hpp:27
prom::Counter & future_continuations_registered()
.then/.on_error continuations registered against a future.
Definition metrics.hpp:252
void warm_up()
Eagerly construct the scope and every metric handle (and, transitively, prom's process-wide adapter c...
Definition metrics.hpp:278
prom::Counter & threads_failed()
ManagedThread bodies that exited by throwing.
Definition metrics.hpp:167
prom::Gauge & threads_live()
ManagedThread bodies currently running (inc on enter, dec on exit).
Definition metrics.hpp:174
prom::Counter & tasks_stuck_detected()
Distinct tasks newly detected as stuck (running past the threshold).
Definition metrics.hpp:212
prom::Counter & pool_scale_downs()
Non-core workers retired after idling out.
Definition metrics.hpp:95
prom::Counter & manager_threads_registered()
Thread control blocks registered with the manager.
Definition metrics.hpp:185
prom::Counter & pool_tasks_cancelled()
Tasks cancelled before running (drained by shutdown_now).
Definition metrics.hpp:64
prom::Gauge & tasks_stuck_current()
Tasks currently flagged as stuck (set from the housekeeper tick).
Definition metrics.hpp:220
prom::Counter & pool_scale_ups()
Non-core workers spawned by a scale-up decision.
Definition metrics.hpp:88
prom::Counter & manager_summaries_published()
Periodic ManagerSummary payloads published to listeners.
Definition metrics.hpp:193
prom::Counter & pool_tasks_submitted()
Tasks submitted to a thread pool (all submit variants).
Definition metrics.hpp:41
prom::Histogram & pool_task_execution_seconds()
Wall-clock seconds a task body spent executing.
Definition metrics.hpp:130
prom::Counter & pool_submit_rejected()
Submissions rejected because the pool was shutting down or terminated.
Definition metrics.hpp:80
prom::Counter & threads_completed()
ManagedThread bodies that returned normally.
Definition metrics.hpp:159
prom::Counter & threads_created()
ManagedThread bodies that entered (started running).
Definition metrics.hpp:152
prom::Gauge & pool_queue_depth()
Tasks currently waiting in a pool's queue (set from the summary tick).
Definition metrics.hpp:102
std::shared_ptr< prom::Scope > & scope()
The shared threadman scope; applies the tm_ prefix to every metric.
Definition metrics.hpp:30
prom::Gauge & pool_workers()
Live workers in a pool (set from the summary tick).
Definition metrics.hpp:109
prom::Gauge & pool_workers_active()
Workers currently executing a task (set from the summary tick).
Definition metrics.hpp:116
prom::Gauge & pool_workers_idle()
Workers currently idle on the queue (set from the summary tick).
Definition metrics.hpp:123
prom::Gauge & manager_pools_live()
Pools currently registered with the manager (set from the summary tick).
Definition metrics.hpp:201
prom::Counter & futures_satisfied_value()
Futures satisfied with a value.
Definition metrics.hpp:238
prom::Counter & pool_tasks_completed()
Tasks that ran to completion on a pool worker.
Definition metrics.hpp:49
prom::Histogram & pool_task_queue_wait_seconds()
Seconds a task waited in the queue before a worker picked it up.
Definition metrics.hpp:139
prom::Counter & future_continuations_dispatched()
Continuations dispatched through an executor.
Definition metrics.hpp:260
prom::Counter & futures_satisfied_exception()
Futures satisfied with an exception.
Definition metrics.hpp:245
prom::Counter & pool_tasks_failed()
Tasks whose body threw an exception.
Definition metrics.hpp:57
prom::Counter & futures_created()
Promise/Future pairs created.
Definition metrics.hpp:231
prom::Counter & pool_queue_rejected()
Submissions rejected because a bounded queue was full.
Definition metrics.hpp:72