-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
86 lines (75 loc) · 1.98 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
package metrics
import (
"context"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/ushakovn/boiler/pkg/config"
)
const (
defaultNamespace = "boiler"
)
var (
defaultCtx = context.Background()
)
func subsystemFromConfig() string {
name := config.ContextClient(defaultCtx).GetAppInfo().Name
name = strings.ToLower(name)
return name
}
func NewCounter(name, help string) prometheus.Counter {
return promauto.NewCounter(prometheus.CounterOpts{
Namespace: defaultNamespace,
Subsystem: subsystemFromConfig(),
Name: name,
Help: help,
})
}
func NewCounterVec(name, help string, labels []string) *prometheus.CounterVec {
return promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: defaultNamespace,
Subsystem: subsystemFromConfig(),
Name: name,
Help: help,
},
labels,
)
}
func NewGauge(name, help string) prometheus.Gauge {
return promauto.NewGauge(prometheus.GaugeOpts{
Namespace: defaultNamespace,
Subsystem: subsystemFromConfig(),
Name: name,
Help: help,
})
}
func NewGaugeVec(name, help string, labels []string) *prometheus.GaugeVec {
return promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: defaultNamespace,
Subsystem: subsystemFromConfig(),
Name: name,
Help: help,
},
labels,
)
}
func NewHistogram(name, help string, buckets []float64) prometheus.Histogram {
return promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: defaultNamespace,
Subsystem: subsystemFromConfig(),
Name: name,
Help: help,
Buckets: buckets,
})
}
func NewHistogramVec(name, help string, buckets []float64, labels []string) *prometheus.HistogramVec {
return promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: defaultNamespace,
Subsystem: subsystemFromConfig(),
Name: name,
Help: help,
Buckets: buckets,
},
labels,
)
}