/
metrics.go
128 lines (112 loc) · 5.38 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
DefaultNamespace = "next"
ComponentNamespace = "component"
BuildInfoGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: DefaultNamespace,
Subsystem: "app",
Name: "build_info",
}, []string{"app_id", "app_name", "app_version", "deploy_env", "go_version", "next_version", "start_time", "build_time"})
// ClientMetricMillisecond is a prometheus histogram for measuring the duration of a request.
ClientMetricMillisecond = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: DefaultNamespace,
Subsystem: "client_requests",
Name: "duration_ms",
Help: "requests duration(ms).",
Buckets: []float64{0.1, 0.5, 1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000},
}, []string{"kind", "callee", "method"})
// ClientMetricRequests is a counter vector of requests.
ClientMetricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: DefaultNamespace,
Subsystem: "client_requests",
Name: "total",
Help: "The total number of processed requests",
}, []string{"kind", "callee", "method", "status"})
// ServerMetricMillisecond is a prometheus histogram for measuring the duration of a request.
ServerMetricMillisecond = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: DefaultNamespace,
Subsystem: "server_requests",
Name: "duration_ms",
Help: "requests duration(ms).",
Buckets: []float64{0.1, 0.5, 1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000},
}, []string{"kind", "caller", "method"})
// ServerMetricRequests is a counter vector of requests.
ServerMetricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: DefaultNamespace,
Subsystem: "server_requests",
Name: "total",
Help: "The total number of processed requests",
}, []string{"kind", "caller", "method", "status"})
// MetricRateLimitTotal is a counter vector of rate limit.
MetricRateLimitTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: DefaultNamespace,
Subsystem: "requests_ratelimit",
Name: "total",
Help: "The total number of ratelimit denied requests",
}, []string{"kind", "caller", "method"})
// DBSystemMetricMillisecond is a prometheus histogram for measuring the duration of a request.
DBSystemMetricMillisecond = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: ComponentNamespace,
Subsystem: "db_system_requests",
Name: "duration_ms",
Help: "requests duration(ms).",
Buckets: []float64{0.1, 0.5, 1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000},
}, []string{"kind", "name", "addr", "command"})
// DBSystemMetricRequests is a counter vector of requests.
DBSystemMetricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: ComponentNamespace,
Subsystem: "db_system_requests",
Name: "total",
Help: "The total number of processed requests",
}, []string{"kind", "name", "addr", "command", "status"})
// DBSystemStatsGauge is a db stats
DBSystemStatsGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: ComponentNamespace,
Name: "db_system_stats",
Help: "The contains database statistics.",
}, []string{"kind", "name", "addr", "index"})
// MessagingProducerMetricMillisecond is a prometheus histogram for measuring the duration of a request.
MessagingProducerMetricMillisecond = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: ComponentNamespace,
Subsystem: "messaging_producer_requests",
Name: "duration_ms",
Help: "requests duration(ms).",
Buckets: []float64{0.1, 0.5, 1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000},
}, []string{"kind", "addr", "destination"})
// MessagingProducerMetricRequests is a counter vector of requests.
MessagingProducerMetricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: ComponentNamespace,
Subsystem: "messaging_producer_requests",
Name: "total",
Help: "The total number of processed requests",
}, []string{"kind", "addr", "destination", "status"})
// MessagingConsumerMetricMillisecond is a prometheus histogram for measuring the duration of a request.
MessagingConsumerMetricMillisecond = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: ComponentNamespace,
Subsystem: "messaging_consumer_requests",
Name: "duration_ms",
Help: "requests duration(ms).",
Buckets: []float64{0.1, 0.5, 1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000},
}, []string{"kind", "addr", "destination", "queue"})
// MessagingConsumerMetricRequests is a counter vector of requests.
MessagingConsumerMetricRequests = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: ComponentNamespace,
Subsystem: "messaging_consumer_requests",
Name: "total",
Help: "The total number of processed requests",
}, []string{"kind", "addr", "destination", "queue", "status"})
)
func init() {
prometheus.MustRegister(
MetricRateLimitTotal,
ClientMetricMillisecond, ClientMetricRequests, // client metrics
ServerMetricMillisecond, ServerMetricRequests, // server metrics
DBSystemMetricMillisecond, DBSystemMetricRequests, // db client metrics
MessagingProducerMetricMillisecond, MessagingProducerMetricRequests, // messaging producer
MessagingConsumerMetricMillisecond, MessagingConsumerMetricRequests, // messaging consumer
BuildInfoGauge, DBSystemStatsGauge,
)
}