MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / sendProvideService

Function sendProvideService

cmd/cql-minerd/provide_service.go:46–175  ·  view source on GitHub ↗
(reg *prometheus.Registry)

Source from the content-addressed store, hash-verified

44)
45
46func sendProvideService(reg *prometheus.Registry) {
47 var (
48 memoryBytes uint64
49 cpuCount float64
50 loadAvg float64
51 keySpace uint64
52 nodeID proto.NodeID
53 privateKey *asymmetric.PrivateKey
54 mf []*dto.MetricFamily
55 err error
56 minerAddr proto.AccountAddress
57 )
58
59 if nodeID, err = kms.GetLocalNodeID(); err != nil {
60 log.WithError(err).Error("get local node id failed")
61 return
62 }
63
64 if privateKey, err = kms.GetLocalPrivateKey(); err != nil {
65 log.WithError(err).Error("get local private key failed")
66 return
67 }
68
69 if minerAddr, err = crypto.PubKeyHash(privateKey.PubKey()); err != nil {
70 log.WithError(err).Error("get miner account address failed")
71 return
72 }
73
74 if mf, err = reg.Gather(); err != nil {
75 log.WithError(err).Error("gathering node metrics failed")
76 return
77 }
78
79 for _, m := range mf {
80 switch m.GetName() {
81 case metricKeyMemory, metricKeyCPUCount, metricKeyLoadAvg, metricKeySpace:
82 default:
83 continue
84 }
85
86 var metricVal float64
87
88 switch m.GetType() {
89 case dto.MetricType_GAUGE:
90 metricVal = m.GetMetric()[0].GetGauge().GetValue()
91 case dto.MetricType_COUNTER:
92 metricVal = m.GetMetric()[0].GetCounter().GetValue()
93 case dto.MetricType_HISTOGRAM:
94 metricVal = m.GetMetric()[0].GetHistogram().GetBucket()[0].GetUpperBound()
95 case dto.MetricType_SUMMARY:
96 metricVal = m.GetMetric()[0].GetSummary().GetQuantile()[0].GetValue()
97 case dto.MetricType_UNTYPED:
98 metricVal = m.GetMetric()[0].GetUntyped().GetValue()
99 default:
100 continue
101 }
102
103 switch m.GetName() {

Callers 1

mainFunction · 0.85

Calls 11

SignMethod · 0.95
GetLocalNodeIDFunction · 0.92
WithErrorFunction · 0.92
GetLocalPrivateKeyFunction · 0.92
PubKeyHashFunction · 0.92
WithFieldsFunction · 0.92
NewProvideServiceFunction · 0.92
ErrorMethod · 0.80
PubKeyMethod · 0.80
InfoMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected