-
Notifications
You must be signed in to change notification settings - Fork 61
/
metrics.go
78 lines (68 loc) · 2.17 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
package mcclient
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const (
metricsNamespace = "imgd"
)
var DefBuckets = []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}
var (
apiClientDuration = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: metricsNamespace,
Subsystem: "mcclient_api",
Name: "duration_seconds",
Help: "Time (in seconds) API requests took.",
Buckets: DefBuckets,
}, []string{"source", "code"},
)
apiClientInflight = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricsNamespace,
Subsystem: "mcclient_api",
Name: "inflight_requests",
Help: "Current number of inflight API requests.",
}, []string{"source"},
)
apiClientTraceDuration = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: metricsNamespace,
Subsystem: "mcclient_api",
Name: "trace_duration_seconds",
Help: "Time (in seconds) since start of API request for events to occur.",
Buckets: DefBuckets,
}, []string{"source", "event"},
)
cacheStatus = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricsNamespace,
Subsystem: "mcclient",
Name: "cache_status",
Help: "Time (in seconds) external API Requests took.",
}, []string{"cache", "status"},
)
)
type cacheStatusRecorder struct {
counter *prometheus.CounterVec
}
func (c *cacheStatusRecorder) Hit() {
c.counter.WithLabelValues("hit").Inc()
}
func (c *cacheStatusRecorder) Miss() {
c.counter.WithLabelValues("miss").Inc()
}
func (c *cacheStatusRecorder) Fresh() {
c.counter.WithLabelValues("fresh").Inc()
}
func (c *cacheStatusRecorder) Stale() {
c.counter.WithLabelValues("stale").Inc()
}
func (c *cacheStatusRecorder) Error() {
c.counter.WithLabelValues("error").Inc()
}
var (
uuidCacheStatus = cacheStatusRecorder{cacheStatus.MustCurryWith(prometheus.Labels{"cache": "CacheUUID"})}
userdataCacheStatus = cacheStatusRecorder{cacheStatus.MustCurryWith(prometheus.Labels{"cache": "CacheUserData"})}
textureCacheStatus = cacheStatusRecorder{cacheStatus.MustCurryWith(prometheus.Labels{"cache": "CacheTextures"})}
)