From 46c99fdcae3c3518a3e4063d0be5780d2c8b6192 Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Thu, 28 Sep 2023 09:15:52 -0500 Subject: [PATCH] Move debug to a common helper --- internal/metrics/fullnode.go | 21 +-------------------- internal/metrics/metrics.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/internal/metrics/fullnode.go b/internal/metrics/fullnode.go index 24ccb11..7ff26db 100644 --- a/internal/metrics/fullnode.go +++ b/internal/metrics/fullnode.go @@ -205,7 +205,7 @@ func (s *FullNodeServiceMetrics) ReceiveResponse(resp *types.WebsocketResponse) case "signage_point": s.SignagePoint(resp) case "debug": - s.Debug(resp) + debugHelper(resp, s.debug) } } @@ -342,25 +342,6 @@ func (s *FullNodeServiceMetrics) SignagePoint(resp *types.WebsocketResponse) { s.currentSignagePoint.Set(float64(signagePoint.BroadcastFarmer.SignagePointIndex)) } -// Debug handles debug events -// Expects map[string]number - where number is able to be parsed into a float64 type -// Assigns the key (string) as the "key" label on the metric, and passes the value straight through -func (s *FullNodeServiceMetrics) Debug(resp *types.WebsocketResponse) { - type debugEvent struct { - Data map[string]float64 `json:"data"` - } - debugMetrics := debugEvent{} - err := json.Unmarshal(resp.Data, &debugMetrics) - if err != nil { - log.Errorf("Error unmarshalling debugMetrics: %s\n", err.Error()) - return - } - - for key, value := range debugMetrics.Data { - s.debug.WithLabelValues(key).Set(value) - } -} - // RefreshFileSizes periodically checks how large files related to the full node are func (s *FullNodeServiceMetrics) RefreshFileSizes() { log.Info("cron: chia_full_node updating file sizes") diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index a6723a8..f1a2184 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -320,3 +320,23 @@ func connectionCountHelper(resp *types.WebsocketResponse, connectionCount *prome connectionCount.WithLabelValues("introducer").Set(introducer) connectionCount.WithLabelValues("wallet").Set(wallet) } + +type debugEvent struct { + Data map[string]float64 `json:"data"` +} + +// debugHelper handles debug events +// Expects map[string]number - where number is able to be parsed into a float64 type +// Assigns the key (string) as the "key" label on the metric, and passes the value straight through +func debugHelper(resp *types.WebsocketResponse, debugGaugeVec *prometheus.GaugeVec) { + debugMetrics := debugEvent{} + err := json.Unmarshal(resp.Data, &debugMetrics) + if err != nil { + log.Errorf("Error unmarshalling debugMetrics: %s\n", err.Error()) + return + } + + for key, value := range debugMetrics.Data { + debugGaugeVec.WithLabelValues(key).Set(value) + } +}