forked from Trendyol/sidecache
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprometheus_exporter.go
More file actions
61 lines (50 loc) · 1.7 KB
/
prometheus_exporter.go
File metadata and controls
61 lines (50 loc) · 1.7 KB
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
package server
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
)
var (
buildInfoGaugeVec = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "sidecache_admission_build_info",
Help: "Build info for sidecache admission webhook",
}, []string{"version"})
cacheHitCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "sidecache_" + ProjectName,
Name: "cache_hit_counter",
Help: "Cache hit count",
})
lockAcquiringAttemptsHistogram = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: "sidecache_" + ProjectName,
Name: "lock_acquiring_attempts_histogram",
Help: "Lock acquiring attempts histogram",
Buckets: []float64{0.999, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 100, 200, 300, 500, 1000},
})
totalRequestCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Namespace: "sidecache_" + ProjectName,
Name: "all_request_hit_counter",
Help: "All request hit counter",
})
)
type Prometheus struct {
CacheHitCounter prometheus.Counter
LockAcquiringAttemptsHistogram prometheus.Histogram
TotalRequestCounter prometheus.Counter
}
func NewPrometheusClient() *Prometheus {
prometheus.MustRegister(buildInfoGaugeVec, cacheHitCounter, lockAcquiringAttemptsHistogram, totalRequestCounter)
return &Prometheus{
CacheHitCounter: cacheHitCounter,
LockAcquiringAttemptsHistogram: lockAcquiringAttemptsHistogram,
TotalRequestCounter: totalRequestCounter,
}
}
func BuildInfo(admission string) {
isNotEmptyAdmissionVersion := len(strings.TrimSpace(admission)) > 0
if isNotEmptyAdmissionVersion {
buildInfoGaugeVec.WithLabelValues(admission)
}
}