From c8ebc8fdf804902768d4d4837610bdac106dbf64 Mon Sep 17 00:00:00 2001 From: Michal Kuratczyk Date: Sat, 30 Nov 2024 19:14:56 +0100 Subject: [PATCH] Don't print message rates until > 0 This prevents printing zeros every second if the clients can't even connect --- pkg/metrics/metrics.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 25eb4be..af93521 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -169,13 +169,14 @@ func (m *MetricsServer) PrintMessageRates(ctx context.Context) { published := MessagesPublished.Get() consumed := MessagesConsumedNormalPriority.Get() + MessagesConsumedHighPriority.Get() - log.Print("", - "published", fmt.Sprintf("%v/s", published-previouslyPublished), - "consumed", fmt.Sprintf("%v/s", consumed-previouslyConsumed)) - - previouslyPublished = published - previouslyConsumed = consumed - + if published > 0 || consumed > 0 { + log.Print("", + "published", fmt.Sprintf("%v/s", published-previouslyPublished), + "consumed", fmt.Sprintf("%v/s", consumed-previouslyConsumed)) + + previouslyPublished = published + previouslyConsumed = consumed + } } } }()