From a78b3dba7f4e9c2d9808151aef857947f5e2ac90 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 19 Jun 2019 18:36:47 +0300 Subject: [PATCH] app/vmstorage: add `vm_cache_entries{type="storage/hour_metric_ids"}` metric for tracking active time series count --- app/vmstorage/main.go | 3 +++ lib/storage/storage.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/vmstorage/main.go b/app/vmstorage/main.go index 535af1380..9b7145744 100644 --- a/app/vmstorage/main.go +++ b/app/vmstorage/main.go @@ -362,6 +362,9 @@ func registerStorageMetrics(strg *storage.Storage) { metrics.NewGauge(`vm_cache_entries{type="storage/date_metricID"}`, func() float64 { return float64(m().DateMetricIDCacheSize) }) + metrics.NewGauge(`vm_cache_entries{type="storage/hour_metric_ids"}`, func() float64 { + return float64(m().HourMetricIDCacheSize) + }) metrics.NewGauge(`vm_cache_entries{type="storage/bigIndexBlocks"}`, func() float64 { return float64(tm().BigIndexBlocksCacheSize) }) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index b77ec8ca7..bc881469b 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -295,6 +295,8 @@ type Metrics struct { DateMetricIDCacheMisses uint64 DateMetricIDCacheCollisions uint64 + HourMetricIDCacheSize uint64 + IndexDBMetrics IndexDBMetrics TableMetrics TableMetrics } @@ -338,6 +340,14 @@ func (s *Storage) UpdateMetrics(m *Metrics) { m.DateMetricIDCacheMisses += cs.Misses m.DateMetricIDCacheCollisions += cs.Collisions + hmCurr := s.currHourMetricIDs.Load().(*hourMetricIDs) + hmPrev := s.prevHourMetricIDs.Load().(*hourMetricIDs) + hourMetricIDsLen := len(hmPrev.m) + if len(hmCurr.m) > hourMetricIDsLen { + hourMetricIDsLen = len(hmCurr.m) + } + m.HourMetricIDCacheSize += uint64(hourMetricIDsLen) + s.idb().UpdateMetrics(&m.IndexDBMetrics) s.tb.UpdateMetrics(&m.TableMetrics) }