From 0c0aab27e7ff9bba10e8710d55c3a7d629412803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Fri, 9 Oct 2026 01:17:00 +0200 Subject: [PATCH] collector: add pprof labels to build and collection (#2562) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan-Otto Kröpke --- README.md | 3 +++ pkg/collector/collect.go | 11 +++++++---- pkg/collector/collection.go | 12 ++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6d6ccb5f..ebffe315 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,9 @@ windows_exporter provides the following HTTP endpoints: * `/health`: Returns 200 OK when the exporter is running. * `/debug/pprof/`: Exposes the [pprof](https://golang.org/pkg/net/http/pprof/) endpoints. Only, if `--debug.enabled` is set. +CPU and goroutine profiles include a `collector` label with the collector name, so profiles can be filtered by collector. +Workers started during collector initialization inherit this label. + ### Using [defaults] with `--collectors.enabled` argument Using `[defaults]` with `--collectors.enabled` argument which gets expanded with all default collectors. diff --git a/pkg/collector/collect.go b/pkg/collector/collect.go index 3ff38953..efa2acf6 100644 --- a/pkg/collector/collect.go +++ b/pkg/collector/collect.go @@ -23,6 +23,7 @@ import ( "fmt" "log/slog" "runtime/debug" + "runtime/pprof" "sync" "time" @@ -85,10 +86,12 @@ func (c *Collection) collectAll(ctx context.Context, ch chan<- prometheus.Metric // timeout handling is done in the execute function for name, metricsCollector := range c.collectors { wg.Go(func() { - collectorStatusCh <- collectorStatus{ - name: name, - statusCode: c.collectCollector(ctx, ch, logger, name, metricsCollector), - } + pprof.Do(ctx, pprof.Labels("collector", name), func(ctx context.Context) { + collectorStatusCh <- collectorStatus{ + name: name, + statusCode: c.collectCollector(ctx, ch, logger, name, metricsCollector), + } + }) }) } diff --git a/pkg/collector/collection.go b/pkg/collector/collection.go index 47c1a058..014ea20c 100644 --- a/pkg/collector/collection.go +++ b/pkg/collector/collection.go @@ -23,6 +23,7 @@ import ( "fmt" "log/slog" "maps" + "runtime/pprof" "slices" gotime "time" @@ -248,10 +249,13 @@ func (c *Collection) Build(ctx context.Context, logger *slog.Logger) error { state := c.state.collector(name) go func() { - resultCh <- buildResult{ - name: collector.GetName(), - err: state.build(ctx, logger, miSession, collector), - } + // Workers started by Build inherit the collector's profiling label. + pprof.Do(ctx, pprof.Labels("collector", name), func(ctx context.Context) { + resultCh <- buildResult{ + name: collector.GetName(), + err: state.build(ctx, logger, miSession, collector), + } + }) }() }