-
Notifications
You must be signed in to change notification settings - Fork 178
/
ping.go
60 lines (51 loc) · 1.68 KB
/
ping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/onflow/flow-go/model/flow"
)
type PingCollector struct {
reachable *prometheus.GaugeVec
sealedHeight *prometheus.GaugeVec
}
func NewPingCollector() *PingCollector {
pc := &PingCollector{
reachable: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "node_reachable",
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Help: "report whether a node is reachable",
}, []string{LabelNodeID, LabelNodeAddress, LabelNodeRole, LabelNodeInfo}),
sealedHeight: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "sealed_height",
Namespace: namespaceNetwork,
Subsystem: subsystemGossip,
Help: "the last sealed height of a node",
}, []string{LabelNodeID, LabelNodeAddress, LabelNodeRole, LabelNodeInfo, LabelNodeVersion}),
}
return pc
}
func (pc *PingCollector) NodeReachable(node *flow.Identity, nodeInfo string, rtt time.Duration) {
var rttValue float64
if rtt > 0 {
rttValue = float64(rtt.Milliseconds())
} else {
rttValue = -1
}
pc.reachable.With(prometheus.Labels{
LabelNodeID: node.NodeID.String(),
LabelNodeAddress: node.Address,
LabelNodeRole: node.Role.String(),
LabelNodeInfo: nodeInfo}).
Set(rttValue)
}
func (pc *PingCollector) NodeInfo(node *flow.Identity, nodeInfo string, version string, sealedHeight uint64) {
pc.sealedHeight.With(prometheus.Labels{
LabelNodeID: node.NodeID.String(),
LabelNodeAddress: node.Address,
LabelNodeRole: node.Role.String(),
LabelNodeInfo: nodeInfo,
LabelNodeVersion: version}).
Set(float64(sealedHeight))
}