From 100eceb6254887c67048e6ad67735d798f84ed7f Mon Sep 17 00:00:00 2001 From: luomingmeng Date: Wed, 18 Oct 2023 21:33:35 +0800 Subject: [PATCH] fix window seconds and add some metrics --- pkg/custom-metric/store/data/cache.go | 8 ++++++++ pkg/custom-metric/store/data/types/aggragated.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/custom-metric/store/data/cache.go b/pkg/custom-metric/store/data/cache.go index 06d7a9c18..b82d4e31b 100644 --- a/pkg/custom-metric/store/data/cache.go +++ b/pkg/custom-metric/store/data/cache.go @@ -29,6 +29,9 @@ import ( const ( metricsNameKCMASStoreDataLatencySet = "kcmas_store_data_latency_set" metricsNameKCMASStoreDataLatencyGet = "kcmas_store_data_latency_get" + + metricsNameKCMASStoreDataLength = "kcmas_store_data_length" + metricsNameKCMASStoreWindowSeconds = "kcmas_store_data_window_seconds" ) // CachedMetric stores all metricItems in an organized way. @@ -215,6 +218,11 @@ func (c *CachedMetric) gcWithTimestamp(expiredTimestamp int64) { internal.gc(expiredTimestamp) if len(internal.seriesMetric.Values) == 0 { delete(internalMap, objectMeta) + } else { + _ = c.emitter.StoreInt64(metricsNameKCMASStoreDataLength, int64(len(internal.seriesMetric.Values)), + metrics.MetricTypeNameRaw, internal.generateTags()...) + _ = c.emitter.StoreInt64(metricsNameKCMASStoreWindowSeconds, (internal.seriesMetric.Values[len(internal.seriesMetric.Values)-1].Timestamp- + internal.seriesMetric.Values[0].Timestamp)/time.Second.Milliseconds(), metrics.MetricTypeNameRaw, internal.generateTags()...) } } if len(internalMap) == 0 { diff --git a/pkg/custom-metric/store/data/types/aggragated.go b/pkg/custom-metric/store/data/types/aggragated.go index 5939cef3d..33768caa0 100644 --- a/pkg/custom-metric/store/data/types/aggragated.go +++ b/pkg/custom-metric/store/data/types/aggragated.go @@ -63,7 +63,7 @@ func (a *AggregatedItem) GetCount() *int64 { return &a.Count } func (a *AggregatedItem) GetTimestamp() int64 { return a.Timestamp } -func (a *AggregatedItem) GetWindowSeconds() *int64 { return &a.Count } +func (a *AggregatedItem) GetWindowSeconds() *int64 { return &a.WindowSeconds } type AggregatedMetric struct { MetricMetaImp `json:",inline"`