-
Notifications
You must be signed in to change notification settings - Fork 178
/
access.go
94 lines (83 loc) · 3.16 KB
/
access.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
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type AccessCollector struct {
connectionReused prometheus.Counter
connectionsInPool *prometheus.GaugeVec
connectionAdded prometheus.Counter
connectionEstablished prometheus.Counter
connectionInvalidated prometheus.Counter
connectionUpdated prometheus.Counter
connectionEvicted prometheus.Counter
}
func NewAccessCollector() *AccessCollector {
ac := &AccessCollector{
connectionReused: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_reused",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times connections get reused",
}),
connectionsInPool: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "connections_in_pool",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of connections in the pool against max number tne pool can hold",
}, []string{"result"}),
connectionAdded: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_added",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times connections are added to the pool",
}),
connectionEstablished: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_established",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times connections are established",
}),
connectionInvalidated: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_invalidated",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times connections are invalidated",
}),
connectionUpdated: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_updated",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times existing connections from the pool are updated",
}),
connectionEvicted: promauto.NewCounter(prometheus.CounterOpts{
Name: "connection_evicted",
Namespace: namespaceAccess,
Subsystem: subsystemConnectionPool,
Help: "counter for the number of times a cached connection is evicted from the connection pool",
}),
}
return ac
}
func (ac *AccessCollector) ConnectionFromPoolReused() {
ac.connectionReused.Inc()
}
func (ac *AccessCollector) TotalConnectionsInPool(connectionCount uint, connectionPoolSize uint) {
ac.connectionsInPool.WithLabelValues("connections").Set(float64(connectionCount))
ac.connectionsInPool.WithLabelValues("pool_size").Set(float64(connectionPoolSize))
}
func (ac *AccessCollector) ConnectionAddedToPool() {
ac.connectionAdded.Inc()
}
func (ac *AccessCollector) NewConnectionEstablished() {
ac.connectionEstablished.Inc()
}
func (ac *AccessCollector) ConnectionFromPoolInvalidated() {
ac.connectionInvalidated.Inc()
}
func (ac *AccessCollector) ConnectionFromPoolUpdated() {
ac.connectionUpdated.Inc()
}
func (ac *AccessCollector) ConnectionFromPoolEvicted() {
ac.connectionEvicted.Inc()
}