Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/crow/metrics.go
4095 views
1
package crow
2
3
import "github.com/prometheus/client_golang/prometheus"
4
5
type metrics struct {
6
totalScrapes prometheus.Counter
7
totalSamples prometheus.Counter
8
totalResults *prometheus.CounterVec
9
pendingSets prometheus.Gauge
10
11
cachedCollectors []prometheus.Collector
12
}
13
14
func newMetrics() *metrics {
15
var m metrics
16
17
m.totalScrapes = prometheus.NewCounter(prometheus.CounterOpts{
18
Name: "crow_test_scrapes_total",
19
Help: "Total number of generated test sample sets",
20
})
21
22
m.totalSamples = prometheus.NewCounter(prometheus.CounterOpts{
23
Name: "crow_test_samples_total",
24
Help: "Total number of generated test samples",
25
})
26
27
m.totalResults = prometheus.NewCounterVec(prometheus.CounterOpts{
28
Name: "crow_test_sample_results_total",
29
Help: "Total validation results of test samples",
30
}, []string{"result"}) // result is either "success", "missing", "mismatch", or "unknown"
31
32
m.pendingSets = prometheus.NewGauge(prometheus.GaugeOpts{
33
Name: "crow_test_pending_validations",
34
Help: "Total number of pending validations to perform",
35
})
36
37
return &m
38
}
39
40
func (m *metrics) collectors() []prometheus.Collector {
41
if m.cachedCollectors == nil {
42
m.cachedCollectors = []prometheus.Collector{
43
m.totalScrapes,
44
m.totalSamples,
45
m.totalResults,
46
m.pendingSets,
47
}
48
}
49
return m.cachedCollectors
50
}
51
52
func (m *metrics) Describe(ch chan<- *prometheus.Desc) {
53
for _, c := range m.collectors() {
54
c.Describe(ch)
55
}
56
}
57
58
func (m *metrics) Collect(ch chan<- prometheus.Metric) {
59
for _, c := range m.collectors() {
60
c.Collect(ch)
61
}
62
}
63
64