From d2e917d1cb8c4487d4523acdcfc066973099184d Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 9 Oct 2020 13:35:48 +0300 Subject: [PATCH] app/vmstorage: add `vm_rows_added_to_storage_total` metric, which shows the total number of rows added to storage since app start --- app/vmstorage/main.go | 3 +++ lib/storage/storage.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/app/vmstorage/main.go b/app/vmstorage/main.go index 6b2d7f3405..aa3235e381 100644 --- a/app/vmstorage/main.go +++ b/app/vmstorage/main.go @@ -371,6 +371,9 @@ func registerStorageMetrics(strg *storage.Storage) { return float64(idbm().SizeBytes) }) + metrics.NewGauge(`vm_rows_added_to_storage_total`, func() float64 { + return float64(m().RowsAddedTotal) + }) metrics.NewGauge(`vm_deduplicated_samples_total{type="merge"}`, func() float64 { return float64(m().DedupsDuringMerge) }) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index ab189ec97c..16bc2133b2 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -333,6 +333,7 @@ func (s *Storage) idb() *indexDB { // Metrics contains essential metrics for the Storage. type Metrics struct { + RowsAddedTotal uint64 DedupsDuringMerge uint64 TooSmallTimestampRows uint64 @@ -401,6 +402,7 @@ func (m *Metrics) Reset() { // UpdateMetrics updates m with metrics from s. func (s *Storage) UpdateMetrics(m *Metrics) { + m.RowsAddedTotal = atomic.LoadUint64(&rowsAddedTotal) m.DedupsDuringMerge = atomic.LoadUint64(&dedupsDuringMerge) m.TooSmallTimestampRows += atomic.LoadUint64(&s.tooSmallTimestampRows) @@ -1127,11 +1129,14 @@ func (s *Storage) ForceMergePartitions(partitionNamePrefix string) error { return s.tb.ForceMergePartitions(partitionNamePrefix) } +var rowsAddedTotal uint64 + // AddRows adds the given mrs to s. func (s *Storage) AddRows(mrs []MetricRow, precisionBits uint8) error { if len(mrs) == 0 { return nil } + atomic.AddUint64(&rowsAddedTotal, uint64(len(mrs))) // Limit the number of concurrent goroutines that may add rows to the storage. // This should prevent from out of memory errors and CPU trashing when too many