Skip to content

Commit 6ce705b

Browse files
zjshen14Yutong Pei
authored and
Yutong Pei
committed
Add node status metrics to prometheus gauge (iotexproject#62)
* Add node status metrics to prometheus gauge * Change metric name convention to lowerCamelCase * Rename the var and change metric and label name to snake_case
1 parent 1924a92 commit 6ce705b

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

server/itx/heartbeat.go

+37-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/json"
1111
"time"
1212

13+
"github.com/prometheus/client_golang/prometheus"
1314
"github.com/zjshen14/go-fsm"
1415

1516
"github.com/iotexproject/iotex-core/consensus"
@@ -22,6 +23,18 @@ import (
2223
// TODO: HeartbeatHandler opens encapsulation of a few structs to inspect the internal status, we need to find a better
2324
// approach to do so in the future
2425

26+
var heartbeatMtc = prometheus.NewGaugeVec(
27+
prometheus.GaugeOpts{
28+
Name: "iotex_heartbeat_status",
29+
Help: "Node heartbeat status.",
30+
},
31+
[]string{"status_type"},
32+
)
33+
34+
func init() {
35+
prometheus.MustRegister(heartbeatMtc)
36+
}
37+
2538
// HeartbeatHandler is the handler to periodically log the system key metrics
2639
type HeartbeatHandler struct {
2740
s *Server
@@ -91,17 +104,30 @@ func (h *HeartbeatHandler) Log() {
91104
height = 0
92105
}
93106

107+
actPoolSize := h.s.actPool.GetSize()
108+
actPoolCapacity := h.s.actPool.GetCapacity()
109+
pendingActs := h.s.actPool.GetUnconfirmedActSize()
110+
94111
logger.Info().
95-
Uint("num-peers", numPeers).
96-
Time("last-out", lastOutTime).
97-
Time("last-in", lastInTime).
98-
Int("dispatcher-events", numDPEvts).
99-
Str("dispatcher-events-audit", string(dpEvtsAudit)).
100-
Int("rolldpos-events", numPendingEvts).
101-
Str("fsm-state", string(state)).
102-
Uint64("height", height).
103-
Uint64("actpool-size", h.s.actPool.GetSize()).
104-
Uint64("actpool-capacity", h.s.actPool.GetCapacity()).
105-
Uint64("actpool-unconfirmed-size", h.s.actPool.GetUnconfirmedActSize()).
112+
Uint("numPeers", numPeers).
113+
Time("lastOut", lastOutTime).
114+
Time("lastIn", lastInTime).
115+
Int("pendingDispatcherEvents", numDPEvts).
116+
Str("pendingDispatcherEventsAudit", string(dpEvtsAudit)).
117+
Int("rolldposEvents", numPendingEvts).
118+
Str("fsmState", string(state)).
119+
Uint64("blockchainHeight", height).
120+
Uint64("actpoolSize", actPoolSize).
121+
Uint64("actpoolCapacity", actPoolCapacity).
122+
Uint64("pendingActions", pendingActs).
106123
Msg("node status")
124+
125+
heartbeatMtc.WithLabelValues("numPeers").Set(float64(numPeers))
126+
heartbeatMtc.WithLabelValues("pendingDispatcherEvents").Set(float64(numDPEvts))
127+
heartbeatMtc.WithLabelValues("pendingRolldposEvents").Set(float64(numPendingEvts))
128+
heartbeatMtc.WithLabelValues("blockchainHeight").Set(float64(height))
129+
heartbeatMtc.WithLabelValues("actpoolSize").Set(float64(actPoolSize))
130+
heartbeatMtc.WithLabelValues("actpoolCapacity").Set(float64(actPoolCapacity))
131+
heartbeatMtc.WithLabelValues("pendingActions").Set(float64(actPoolCapacity))
132+
107133
}

0 commit comments

Comments
 (0)