-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmetrics.go
51 lines (41 loc) · 1.49 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
package metrics
import (
"fmt"
"time"
)
// EventStoreLatency records eventstore latency for a named op.
func EventStoreLatency(op string, start time.Time) {
eventStoreTimer.WithLabelValues("Find").Observe(msSince(start))
}
// DBError increments a counter for a db error operation.
func DBError(op string) {
eventStoreDbErrCounter.WithLabelValues(op).Inc()
}
// GRPCLatency records grpc request latency for a named method.
func GRPCLatency(method string, start time.Time) {
grpcReqLatencies.WithLabelValues(method).Observe(msSince(start))
}
// GRPCSuccess counts successful gPRC calls by method.
func GRPCSuccess(method string) {
grpcRespCounter.WithLabelValues(method, "0").Inc()
}
// GRPCFailure counts failed gPRC calls by method.
func GRPCFailure(method string) {
grpcRespCounter.WithLabelValues(method, "1").Inc()
}
// RsyslogLatency records rsyslog latency.
func RsyslogLatency(start time.Time) {
rsyslogReqLatencies.WithLabelValues().Observe(msSince(start))
}
// HTTPLatency records a request latency for a given url path.
func HTTPLatency(path string, start time.Time) {
httpReqLatencies.WithLabelValues(path).Observe(msSince(start))
}
// HTTPStatus records counts of http statuses, bucketed according to status types.
func HTTPStatus(path string, status int) {
httpStatus.WithLabelValues(path, fmt.Sprintf("%d", bucketHTTPStatus(status))).Inc()
}
// bucketHTTPStatus rounds down to the nearest hundred to facilitate categorizing http statuses.
func bucketHTTPStatus(i int) int {
return i - i%100
}