This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmetrics.go
140 lines (124 loc) · 4.3 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package main
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
cacheCountTotal prometheus.Gauge
cacheDuration prometheus.ObserverVec
cacheErrors *prometheus.CounterVec
cacheHits *prometheus.CounterVec
cacheInFlight *prometheus.GaugeVec
cacheStalls *prometheus.CounterVec
cacheTotals *prometheus.CounterVec
cacherState prometheus.Gauge
ingestCount *prometheus.CounterVec
ingestDuration *prometheus.GaugeVec
ingestErrors *prometheus.CounterVec
watchMissTotal prometheus.Counter
)
func setupMetrics() {
cacheCountTotal = promauto.NewGauge(prometheus.GaugeOpts{
Name: "cache_count_total",
Help: "Number of in devices in memory.",
})
cacheDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "cache_ops_duration_seconds",
Help: "Duration of cache operations",
Buckets: prometheus.LinearBuckets(.01, .1, 10),
}, []string{"method", "op"})
cacheErrors = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cache_ops_errors_total",
Help: "Number of cache errors.",
}, []string{"method", "op"})
cacheHits = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cache_hit_total",
Help: "Number of cache hits.",
}, []string{"method", "op"})
cacheInFlight = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "cache_ops_current_total",
Help: "Number of in flight cache requests.",
}, []string{"method", "op"})
cacheStalls = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cache_stall_total",
Help: "Number of cache stalled due to DB.",
}, []string{"method", "op"})
cacheTotals = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cache_ops_total",
Help: "Number of cache ops.",
}, []string{"method", "op"})
logger.Info("initializing label values")
var labels []prometheus.Labels
labels = []prometheus.Labels{
{"method": "Push", "op": ""},
{"method": "Ingest", "op": ""},
}
initCounterLabels(cacheErrors, labels)
initGaugeLabels(cacheInFlight, labels)
initCounterLabels(cacheStalls, labels)
initCounterLabels(cacheTotals, labels)
labels = []prometheus.Labels{
{"method": "Push", "op": "insert"},
{"method": "Push", "op": "delete"},
}
initObserverLabels(cacheDuration, labels)
initCounterLabels(cacheHits, labels)
labels = []prometheus.Labels{
{"method": "ByMAC", "op": "get"},
{"method": "ByIP", "op": "get"},
{"method": "ByID", "op": "get"},
{"method": "All", "op": "get"},
{"method": "Ingest", "op": ""},
{"method": "Watch", "op": "get"},
{"method": "Watch", "op": "push"},
}
initCounterLabels(cacheErrors, labels)
initGaugeLabels(cacheInFlight, labels)
initCounterLabels(cacheStalls, labels)
initCounterLabels(cacheTotals, labels)
initObserverLabels(cacheDuration, labels)
initCounterLabels(cacheHits, labels)
cacherState = promauto.NewGauge(prometheus.GaugeOpts{
Name: "cacher_state",
Help: "Reports cacher state, 0:started, 1:ingesting, 2:ready",
})
ingestCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "ingest_op_count_total",
Help: "Number of attempts made to ingest facility data.",
}, []string{"method", "op"})
ingestDuration = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "ingest_op_duration_seconds",
Help: "Duration of successful ingestion actions while attempting to ingest facility data.",
}, []string{"method", "op"})
ingestErrors = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "ingest_error_count_total",
Help: "Number of errors occurred attempting to ingest facility data.",
}, []string{"method", "op"})
labels = []prometheus.Labels{
{"method": "Ingest", "op": ""},
{"method": "Ingest", "op": "fetch"},
{"method": "Ingest", "op": "copy"},
}
initCounterLabels(ingestCount, labels)
initGaugeLabels(ingestDuration, labels)
initCounterLabels(ingestErrors, labels)
watchMissTotal = promauto.NewCounter(prometheus.CounterOpts{
Name: "watch_miss_count_total",
Help: "Number of missed updates due to a blocked channel.",
})
}
func initObserverLabels(m prometheus.ObserverVec, l []prometheus.Labels) {
for _, labels := range l {
m.With(labels)
}
}
func initGaugeLabels(m *prometheus.GaugeVec, l []prometheus.Labels) {
for _, labels := range l {
m.With(labels)
}
}
func initCounterLabels(m *prometheus.CounterVec, l []prometheus.Labels) {
for _, labels := range l {
m.With(labels)
}
}