github.com/koko1123/flow-go-1@v0.29.6/module/metrics/node_info.go (about) 1 package metrics 2 3 import ( 4 "strconv" 5 6 "github.com/prometheus/client_golang/prometheus" 7 "github.com/prometheus/client_golang/prometheus/promauto" 8 ) 9 10 // NodeInfoCollector implements metrics to report static information about node. 11 // Such information can include: version, commit, sporkID. 12 type NodeInfoCollector struct { 13 nodeInfo *prometheus.GaugeVec 14 } 15 16 const ( 17 sporkIDLabel = "spork_id" 18 versionLabel = "version" 19 commitLabel = "commit" 20 protocolVersionLabel = "protocol_version" 21 ) 22 23 func NewNodeInfoCollector() *NodeInfoCollector { 24 collector := &NodeInfoCollector{ 25 nodeInfo: promauto.NewGaugeVec(prometheus.GaugeOpts{ 26 Name: "node_info", 27 Namespace: "general", 28 Help: "report general information about node, such information can include version, sporkID, commit hash, etc", 29 }, []string{"key", "value"}), 30 } 31 32 return collector 33 } 34 35 func (sc *NodeInfoCollector) NodeInfo(version, commit, sporkID string, protocolVersion uint) { 36 sc.nodeInfo.WithLabelValues(versionLabel, version) 37 sc.nodeInfo.WithLabelValues(commitLabel, commit) 38 sc.nodeInfo.WithLabelValues(sporkIDLabel, sporkID) 39 sc.nodeInfo.WithLabelValues(protocolVersionLabel, strconv.FormatUint(uint64(protocolVersion), 10)) 40 }