-
Notifications
You must be signed in to change notification settings - Fork 179
/
ping.go
42 lines (35 loc) · 1021 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
37
38
39
40
41
42
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
}
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}),
}
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)
}