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
This commit is contained in:
Aliaksandr Valialkin 2021-05-20 15:27:06 +03:00
parent ad73f226ff
commit e394ff6466
2 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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.