-
Notifications
You must be signed in to change notification settings - Fork 211
/
metrics.go
71 lines (61 loc) · 1.61 KB
/
metrics.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package blocks
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/spacemeshos/go-spacemesh/metrics"
)
const (
namespace = "blocks"
// labels for block generation.
failFetch = "fail_proposal"
failGen = "fail_block"
internalErr = "fail_error"
genBlock = "block"
empty = "empty"
labelEpoch = "epoch"
)
var (
blockGenCount = metrics.NewCounter(
"generate",
namespace,
"number of block generation",
[]string{"outcome"},
)
blockOkCnt = blockGenCount.WithLabelValues(genBlock)
emptyOutputCnt = blockGenCount.WithLabelValues(empty)
failFetchCnt = blockGenCount.WithLabelValues(failFetch)
failGenCnt = blockGenCount.WithLabelValues(failGen)
failErrCnt = blockGenCount.WithLabelValues(internalErr)
)
type collector struct {
*Certifier
epochCertCount *prometheus.Desc
}
func newCollector(certifier *Certifier) *collector {
c := &collector{
Certifier: certifier,
epochCertCount: prometheus.NewDesc(
prometheus.BuildFQName(metrics.Namespace, namespace, "cert_count"),
"number of certificate created/synced in each epoch",
[]string{labelEpoch},
nil,
),
}
if err := prometheus.Register(c); err != nil {
_, ok := err.(prometheus.AlreadyRegisteredError)
if !ok {
panic(err)
}
}
return c
}
func (c *collector) Stop() {
prometheus.Unregister(c)
}
func (c *collector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.epochCertCount
}
func (c *collector) Collect(ch chan<- prometheus.Metric) {
for epoch, cnt := range c.CertCount() {
ch <- prometheus.MustNewConstMetric(c.epochCertCount, prometheus.CounterValue, float64(cnt), epoch.String())
}
}