From e394ff646678789567da257c31bdab32fb96bd37 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 20 May 2021 15:27:06 +0300 Subject: [PATCH] app/vmagent/remotewrite: expose metrics with the current number of active series per day and per hour These numbers are exposed via the following metrics: - vmagent_hourly_series_limit_current_series - vmagent_daily_series_limit_current_series Expose also the limits via the following metrics: - vmagent_hourly_series_limit_max_series - vmagent_daily_series_limit_max_series --- app/vmagent/remotewrite/remotewrite.go | 12 ++++++++++++ lib/bloomfilter/limiter.go | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/app/vmagent/remotewrite/remotewrite.go b/app/vmagent/remotewrite/remotewrite.go index 36f5b7e69..17bb379b0 100644 --- a/app/vmagent/remotewrite/remotewrite.go +++ b/app/vmagent/remotewrite/remotewrite.go @@ -81,9 +81,21 @@ func Init() { } if *maxHourlySeries > 0 { hourlySeriesLimiter = bloomfilter.NewLimiter(*maxHourlySeries, time.Hour) + _ = metrics.NewGauge(`vmagent_hourly_series_limit_max_series`, func() float64 { + return float64(hourlySeriesLimiter.MaxItems()) + }) + _ = metrics.NewGauge(`vmagent_hourly_series_limit_current_series`, func() float64 { + return float64(hourlySeriesLimiter.CurrentItems()) + }) } if *maxDailySeries > 0 { dailySeriesLimiter = bloomfilter.NewLimiter(*maxDailySeries, 24*time.Hour) + _ = metrics.NewGauge(`vmagent_daily_series_limit_max_series`, func() float64 { + return float64(dailySeriesLimiter.MaxItems()) + }) + _ = metrics.NewGauge(`vmagent_daily_series_limit_current_series`, func() float64 { + return float64(dailySeriesLimiter.CurrentItems()) + }) } if *queues > maxQueues { *queues = maxQueues diff --git a/lib/bloomfilter/limiter.go b/lib/bloomfilter/limiter.go index d07788baf..152d999b0 100644 --- a/lib/bloomfilter/limiter.go +++ b/lib/bloomfilter/limiter.go @@ -33,6 +33,13 @@ func (l *Limiter) MaxItems() int { return l.maxItems } +// CurrentItems return the current number of items registered in l. +func (l *Limiter) CurrentItems() int { + lm := l.v.Load().(*limiter) + n := atomic.LoadUint64(&lm.currentItems) + return int(n) +} + // Add adds h to the limiter. // // It is safe calling Add from concurrent goroutines.