Skip to content

Commit 00fc9e6

Browse files
authored
top metrics (#79)
2 parents 30e2550 + 9c0440c commit 00fc9e6

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

cmd/thanos/receive.go

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

443+
level.Debug(logger).Log("msg", "setting up periodic top metrics collection")
444+
{
445+
topMetricNumSeries := promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
446+
Name: "thanos_receive_top_metric_num_series",
447+
Help: "Number of series in top metric.",
448+
}, []string{"tenant", "metric_name"})
449+
ctx, cancel := context.WithCancel(context.Background())
450+
g.Add(func() error {
451+
return runutil.Repeat(conf.topMetricsUpdateInterval, ctx.Done(), func() error {
452+
level.Error(logger).Log("msg", "getting top metrics")
453+
for _, ts := range dbs.TenantStats(conf.numTopMetricsPerTenant, labels.MetricName) {
454+
for _, ms := range ts.Stats.IndexPostingStats.CardinalityMetricsStats {
455+
if ms.Count >= conf.topMetricsMinimumCardinality {
456+
topMetricNumSeries.WithLabelValues(ts.Tenant, ms.Name).Set(float64(ms.Count))
457+
}
458+
}
459+
}
460+
return nil
461+
})
462+
}, func(err error) {
463+
cancel()
464+
})
465+
}
466+
443467
{
444468
if limiter.CanReload() {
445469
ctx, cancel := context.WithCancel(context.Background())
@@ -853,6 +877,10 @@ type receiveConfig struct {
853877
limitsConfigReloadTimer time.Duration
854878

855879
asyncForwardWorkerCount uint
880+
881+
numTopMetricsPerTenant int
882+
topMetricsMinimumCardinality uint64
883+
topMetricsUpdateInterval time.Duration
856884
}
857885

858886
func (rc *receiveConfig) registerFlag(cmd extkingpin.FlagClause) {
@@ -997,6 +1025,13 @@ func (rc *receiveConfig) registerFlag(cmd extkingpin.FlagClause) {
9971025
rc.writeLimitsConfig = extflag.RegisterPathOrContent(cmd, "receive.limits-config", "YAML file that contains limit configuration.", extflag.WithEnvSubstitution(), extflag.WithHidden())
9981026
cmd.Flag("receive.limits-config-reload-timer", "Minimum amount of time to pass for the limit configuration to be reloaded. Helps to avoid excessive reloads.").
9991027
Default("1s").Hidden().DurationVar(&rc.limitsConfigReloadTimer)
1028+
1029+
cmd.Flag("receive.num-top-metrics-per-tenant", "The number of top metrics to track for each tenant.").
1030+
Default("100").IntVar(&rc.numTopMetricsPerTenant)
1031+
cmd.Flag("receive.top-metrics-minimum-cardinality", "The minimum cardinality for a metric to be considered top metric.").
1032+
Default("10000").Uint64Var(&rc.topMetricsMinimumCardinality)
1033+
cmd.Flag("receive.top-metrics-update-interval", "The interval at which the top metrics are updated.").
1034+
Default("5m").DurationVar(&rc.topMetricsUpdateInterval)
10001035
}
10011036

10021037
// determineMode returns the ReceiverMode that this receiver is configured to run in.

0 commit comments

Comments
 (0)