-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
96 lines (79 loc) · 1.84 KB
/
types.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
package bprometheus
import (
"time"
"github.com/go-masonry/mortar/interfaces/monitor"
"github.com/prometheus/client_golang/prometheus"
)
type promCounterVec struct {
*prometheus.CounterVec
}
type promCounter struct {
prometheus.Counter
}
type promGaugeVec struct {
*prometheus.GaugeVec
}
type promGauge struct {
prometheus.Gauge
}
type promHistogramVec struct {
*prometheus.HistogramVec
}
type promHistogram struct {
prometheus.Observer
}
type promTimerVec struct {
*prometheus.HistogramVec
}
type promTimer struct {
prometheus.Observer
}
func (p *promCounterVec) WithTags(tags map[string]string) (monitor.Counter, error) {
counter, err := p.GetMetricWith(tags)
if err != nil {
return nil, err
}
return &promCounter{
Counter: counter,
}, nil
}
func (p *promGaugeVec) WithTags(tags map[string]string) (monitor.Gauge, error) {
gauge, err := p.GetMetricWith(tags)
if err != nil {
return nil, err
}
return &promGauge{
Gauge: gauge,
}, nil
}
func (p *promHistogramVec) WithTags(tags map[string]string) (monitor.Histogram, error) {
histogram, err := p.GetMetricWith(tags)
if err != nil {
return nil, err
}
return &promHistogram{
Observer: histogram,
}, nil
}
func (p *promHistogram) Record(v float64) {
p.Observe(v)
}
func (p *promTimerVec) WithTags(tags map[string]string) (monitor.Timer, error) {
histogram, err := p.GetMetricWith(tags)
if err != nil {
return nil, err
}
return &promTimer{
Observer: histogram,
}, nil
}
func (p *promTimer) Record(d time.Duration) {
p.Observe(d.Seconds())
}
var _ monitor.BricksCounter = (*promCounterVec)(nil)
var _ monitor.Counter = (*promCounter)(nil)
var _ monitor.BricksGauge = (*promGaugeVec)(nil)
var _ monitor.Gauge = (*promGauge)(nil)
var _ monitor.BricksHistogram = (*promHistogramVec)(nil)
var _ monitor.Histogram = (*promHistogram)(nil)
var _ monitor.Timer = (*promTimer)(nil)