Skip to content

Commit

Permalink
Move debug to a common helper
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Sep 28, 2023
1 parent 77f2fc0 commit 46c99fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
21 changes: 1 addition & 20 deletions internal/metrics/fullnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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")
Expand Down
20 changes: 20 additions & 0 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 46c99fd

Please sign in to comment.