Add a metric for CPU time per thread type

`synapse_thread_cpu_seconds_total{thread_type, mode}` reads
`/proc/self/task` on each scrape and groups threads into the main thread,
each registered threadpool, tokio (by kernel thread name), and `other`.

The kernel only reports CPU time for live threads, so the collector sums
per-thread deltas between scrapes. A thread that exits loses the CPU it
used since the last scrape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EDruzqbGMzEHotouLuudxP
This commit is contained in:
Erik JohnstonandClaude Opus 5.5 committed 2026-10-26 15:38:17 +00:00
1 parent d99e5fe783
commit 35cd879f37
4 files changed
+183

No files matched your search

+1
View File
@@ -147,6 +147,7 @@ prometheus_metric_fullname_to_label_arg_map: Mapping[str, ArgLocation | None] =
"synapse.metrics._gc.PyPyGCStats": None,
"synapse.metrics._reactor_metrics.ReactorLastSeenMetric": None,
"synapse.metrics.CPUMetrics": None,
"synapse.metrics._thread_cpu.ThreadCPUMetrics": None,
"synapse.metrics.jemalloc.JemallocCollector": None,
"synapse.util.metrics.DynamicCollectorRegistry": None,
"synapse.metrics.background_process_metrics._Collector": None,