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) + } +}