-
Notifications
You must be signed in to change notification settings - Fork 175
/
ping.go
36 lines (31 loc) · 875 Bytes
/
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
package metrics
import (
"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
}
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, LabelNodeRole, LabelNodeInfo}),
}
return pc
}
func (pc *PingCollector) NodeReachable(node *flow.Identity, nodeInfo string, reachable bool) {
var val float64
if reachable {
val = 1
}
pc.reachable.With(prometheus.Labels{
LabelNodeID: node.String(),
LabelNodeRole: node.Role.String(),
LabelNodeInfo: nodeInfo}).
Set(val)
}