Skip to content

Commit 9d14915

Browse files
committed
add top metrics
1 parent 30e2550 commit 9d14915

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

cmd/thanos/receive.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,29 @@ func runReceive(
440440
})
441441
}
442442

443+
level.Debug(logger).Log("msg", "setting up periodic top metrics collection")
444+
topMetricsSeriesCount := promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
445+
Name: "thanos_receive_top_metrics_series_count",
446+
Help: "Number of series in top metrics.",
447+
}, []string{"tenant", "metric_name"})
448+
{
449+
ctx, cancel := context.WithCancel(context.Background())
450+
g.Add(func() error {
451+
return runutil.Repeat(30*time.Second, ctx.Done(), func() error {
452+
level.Error(logger).Log("msg", "getting top metrics")
453+
for _, ts := range dbs.TenantStats(10, labels.MetricName) {
454+
for _, ms := range ts.Stats.IndexPostingStats.CardinalityMetricsStats {
455+
level.Error(logger).Log("msg", "tenant", ts.Tenant, "metric_name", ms.Name, "count", ms.Count)
456+
topMetricsSeriesCount.WithLabelValues(ts.Tenant, ms.Name).Set(float64(ms.Count))
457+
}
458+
}
459+
return nil
460+
})
461+
}, func(err error) {
462+
cancel()
463+
})
464+
}
465+
443466
{
444467
if limiter.CanReload() {
445468
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)