-
Notifications
You must be signed in to change notification settings - Fork 177
/
loader.go
68 lines (57 loc) · 1.91 KB
/
loader.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
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type LoaderCollector struct {
transactionsSent prometheus.Counter
transactionsLost prometheus.Counter
tpsConfigured prometheus.Gauge
transactionsExecuted prometheus.Counter
tteInSeconds prometheus.Histogram
}
func NewLoaderCollector() *LoaderCollector {
cc := &LoaderCollector{
transactionsSent: promauto.NewCounter(prometheus.CounterOpts{
Name: "transactions_sent",
Namespace: namespaceLoader,
Help: "transactions sent by the loader",
}),
transactionsLost: promauto.NewCounter(prometheus.CounterOpts{
Name: "transactions_lost",
Namespace: namespaceLoader,
Help: "transaction that took too long to return",
}),
tpsConfigured: promauto.NewGauge(prometheus.GaugeOpts{
Name: "transactions_per_second_configured",
Namespace: namespaceLoader,
Help: "transactions per second that the loader should send",
}),
transactionsExecuted: promauto.NewCounter(prometheus.CounterOpts{
Name: "transactions_executed",
Namespace: namespaceLoader,
Help: "transaction successfully executed by the loader",
}),
tteInSeconds: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "transactions_executed_in_seconds",
Namespace: namespaceLoader,
Help: "Time To Execute histogram for transactions (in seconds)",
Buckets: prometheus.ExponentialBuckets(2, 2, 8),
}),
}
return cc
}
func (cc *LoaderCollector) TransactionSent() {
cc.transactionsSent.Inc()
}
func (cc *LoaderCollector) TransactionLost() {
cc.transactionsLost.Inc()
}
func (cc *LoaderCollector) SetTPSConfigured(tps uint) {
cc.tpsConfigured.Set(float64(tps))
}
func (cc *LoaderCollector) TransactionExecuted(duration time.Duration) {
cc.transactionsExecuted.Inc()
cc.tteInSeconds.Observe(float64(duration.Seconds()))
}