-
Notifications
You must be signed in to change notification settings - Fork 175
/
node_info.go
40 lines (33 loc) · 1.2 KB
/
node_info.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
package metrics
import (
"strconv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// NodeInfoCollector implements metrics to report static information about node.
// Such information can include: version, commit, sporkID.
type NodeInfoCollector struct {
nodeInfo *prometheus.GaugeVec
}
const (
sporkIDLabel = "spork_id"
versionLabel = "version"
commitLabel = "commit"
protocolVersionLabel = "protocol_version"
)
func NewNodeInfoCollector() *NodeInfoCollector {
collector := &NodeInfoCollector{
nodeInfo: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "node_info",
Namespace: "general",
Help: "report general information about node, such information can include version, sporkID, commit hash, etc",
}, []string{"key", "value"}),
}
return collector
}
func (sc *NodeInfoCollector) NodeInfo(version, commit, sporkID string, protocolVersion uint) {
sc.nodeInfo.WithLabelValues(versionLabel, version)
sc.nodeInfo.WithLabelValues(commitLabel, commit)
sc.nodeInfo.WithLabelValues(sporkIDLabel, sporkID)
sc.nodeInfo.WithLabelValues(protocolVersionLabel, strconv.FormatUint(uint64(protocolVersion), 10))
}