-
Notifications
You must be signed in to change notification settings - Fork 8
/
metrics.go
96 lines (83 loc) · 2.44 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package metric
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/xmidt-org/touchstone"
"go.uber.org/fx"
)
// Metric names.
const (
// Common across data backends.
QueryDurationSecondsHistogram = "db_query_duration_seconds"
QueriesCounter = "db_queries_total"
// DynamoDB-specific metrics.
DynamodbConsumedCapacityCounter = "dynamodb_consumed_capacity_total"
DynamodbGetAllGauge = "dynamodb_get_all_results"
)
// Metric label keys.
const (
QueryOutcomeLabelKey = "outcome"
QueryTypeLabelKey = "type"
DynamoCapacityOpLabelKey = "op"
)
// Metric label values for DAO operation types.
const (
GetQueryType = "get"
GetAllQueryType = "getall"
DeleteQueryType = "delete"
PushQueryType = "push"
PingQueryType = "ping"
)
// Metric label values for Query Outcomes.
const (
FailQueryOutcome = "fail"
SuccessQueryOutcome = "success"
)
// Metric label values for DynamoDB Consumed capacity type
const (
DynamoCapacityReadOp = "read"
DynamoCapacityWriteOp = "write"
)
// ProvideMetrics returns the Metrics relevant to this package
func ProvideMetrics() fx.Option {
return fx.Options(
touchstone.CounterVec(
prometheus.CounterOpts{
Name: QueriesCounter,
Help: "The total number of DB queries Argus has performed.",
},
QueryOutcomeLabelKey,
QueryTypeLabelKey,
),
touchstone.HistogramVec(
prometheus.HistogramOpts{
Name: QueryDurationSecondsHistogram,
Help: "A histogram of latencies for queries.",
Buckets: []float64{0.0625, 0.125, .25, .5, 1, 5, 10, 20, 40, 80, 160},
},
QueryTypeLabelKey,
),
touchstone.CounterVec(
prometheus.CounterOpts{
Name: DynamodbConsumedCapacityCounter,
Help: "Capacity units consumed by the DynamoDB operation.",
},
QueryTypeLabelKey,
DynamoCapacityOpLabelKey,
),
touchstone.Gauge(
prometheus.GaugeOpts{
Name: DynamodbGetAllGauge,
Help: "Amount of records returned for a GetAll dynamodb request.",
},
),
)
}
type Measures struct {
fx.In
Queries *prometheus.CounterVec `name:"db_queries_total"`
QueryDurationSeconds prometheus.ObserverVec `name:"db_query_duration_seconds"`
DynamodbConsumedCapacity *prometheus.CounterVec `name:"dynamodb_consumed_capacity_total"`
DynamodbGetAllGauge prometheus.Gauge `name:"dynamodb_get_all_results"`
}