-
Notifications
You must be signed in to change notification settings - Fork 342
/
stats.go
31 lines (26 loc) · 963 Bytes
/
stats.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
package gs
import (
"strconv"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var durationHistograms = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "gs_operation_duration_seconds",
Help: "durations of outgoing gs operations",
},
[]string{"operation", "error"})
var requestSizeHistograms = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "gs_operation_size_bytes",
Help: "handled sizes of outgoing gs operations",
Buckets: prometheus.ExponentialBuckets(1, 10, 10),
}, []string{"operation", "error"})
func reportMetrics(operation string, start time.Time, sizeBytes *int64, err *error) {
isErrStr := strconv.FormatBool(*err != nil)
durationHistograms.WithLabelValues(operation, isErrStr).Observe(time.Since(start).Seconds())
if sizeBytes != nil {
requestSizeHistograms.WithLabelValues(operation, isErrStr).Observe(float64(*sizeBytes))
}
}