/
metrics.go
61 lines (54 loc) · 1.72 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
package esmc
import (
"github.com/prometheus/client_golang/prometheus"
"time"
)
var (
requestCount = prometheus.NewCounter()
requestDuration = prometheus.NewCounter()
requestDurations = prometheus.NewDefaultHistogram()
reportedRequestDuration = prometheus.NewCounter()
reportedRequestDurations = prometheus.NewDefaultHistogram()
)
func updateRequestMetrics(labels map[string]string, duration time.Duration) {
requestCount.Increment(labels)
requestDuration.IncrementBy(labels, float64(duration))
requestDurations.Add(labels, float64(duration))
}
func updateReportedMetrics(labels map[string]string, took int) {
duration := float64(time.Duration(took) * time.Millisecond)
reportedRequestDuration.IncrementBy(labels, duration)
reportedRequestDurations.Add(labels, duration)
}
func init() {
prometheus.Register(
"esmc_requests",
"A counter of the total number of requests to an ES cluster",
prometheus.NilLabels,
requestCount,
)
prometheus.Register(
"esmc_request_total_duration_nanoseconds",
"The total amount of time spent executing requests (nanoseconds)",
prometheus.NilLabels,
requestDuration,
)
prometheus.Register(
"esmc_request_durations_nanoseconds",
"The amounts of time spent executing requests (nanoseconds)",
prometheus.NilLabels,
requestDurations,
)
prometheus.Register(
"esmc_reported_request_total_duration_nanoseconds",
"The total amount of time spent executing requests as reported by elasticsearch (nanoseconds)",
prometheus.NilLabels,
reportedRequestDuration,
)
prometheus.Register(
"esmc_reported_request_durations_nanoseconds",
"The amounts of time spent executing requests as reported by elasticsearch (nanoseconds)",
prometheus.NilLabels,
reportedRequestDurations,
)
}