-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics.go
63 lines (53 loc) · 2.06 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
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
// SendAmount tracks metrics related to Send API of dispendium. It tracks the spending output.
SendAmount = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "dispendium",
Subsystem: "sending",
Name: "amount",
Help: "Tracks the send amounts for the api",
}, []string{"instance"})
// sendDur tracks metrics related to Send API of Dispendium. It tracks how long it takes for the sending to complete.
sendDur = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "dispendium",
Subsystem: "sending",
Name: "duration",
Help: "Tracks the send durations for the api",
}, []string{"instance"})
// Sending tracks the number of active sends from lbrycrd at a time
Sending = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "dispendium",
Subsystem: "sending",
Name: "now",
Help: "number active sends happening now",
}, []string{"instance"})
// apiDuration It tracks how long it takes for the api's of Dispendium to complete.
apiDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "dispendium",
Subsystem: "api",
Name: "duration",
Help: "Tracks the durations for an api",
}, []string{"api"})
// Balance tracks the balance of each wallet whenever we call get balance.
Balance = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "dispendium",
Subsystem: "lbrycrd",
Name: "balance",
Help: "Tracks the send durations for the api",
}, []string{"instance"})
)
// SendDuration logs the time it takes to send with the respective metric
func SendDuration(start time.Time, instance string) {
duration := time.Since(start).Seconds()
sendDur.WithLabelValues(instance).Observe(duration)
}
// APIDuration logs the time it takes to complete the api with the respective metric
func APIDuration(start time.Time, api string) {
duration := time.Since(start).Seconds()
apiDuration.WithLabelValues(api).Observe(duration)
}