forked from hyperledger/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
95 lines (88 loc) · 3.19 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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package grpcmetrics
import "github.com/hyperledger/fabric/common/metrics"
var (
unaryRequestDuration = metrics.HistogramOpts{
Namespace: "grpc",
Subsystem: "server",
Name: "unary_request_duration",
Help: "The time to complete a unary request.",
LabelNames: []string{"service", "method", "code"},
StatsdFormat: "%{#fqname}.%{service}.%{method}.%{code}",
}
unaryRequestsReceived = metrics.CounterOpts{
Namespace: "grpc",
Subsystem: "server",
Name: "unary_requests_received",
Help: "The number of unary requests received.",
LabelNames: []string{"service", "method"},
StatsdFormat: "%{#fqname}.%{service}.%{method}",
}
unaryRequestsCompleted = metrics.CounterOpts{
Namespace: "grpc",
Subsystem: "server",
Name: "unary_requests_completed",
Help: "The number of unary requests completed.",
LabelNames: []string{"service", "method", "code"},
StatsdFormat: "%{#fqname}.%{service}.%{method}.%{code}",
}
streamRequestDuration = metrics.HistogramOpts{
Namespace: "grpc",
Subsystem: "server",
Name: "stream_request_duration",
Help: "The time to complete a stream request.",
LabelNames: []string{"service", "method", "code"},
StatsdFormat: "%{#fqname}.%{service}.%{method}.%{code}",
}
streamRequestsReceived = metrics.CounterOpts{
Namespace: "grpc",
Subsystem: "server",
Name: "stream_requests_received",
Help: "The number of stream requests received.",
LabelNames: []string{"service", "method"},
StatsdFormat: "%{#fqname}.%{service}.%{method}",
}
streamRequestsCompleted = metrics.CounterOpts{
Namespace: "grpc",
Subsystem: "server",
Name: "stream_requests_completed",
Help: "The number of stream requests completed.",
LabelNames: []string{"service", "method", "code"},
StatsdFormat: "%{#fqname}.%{service}.%{method}.%{code}",
}
streamMessagesReceived = metrics.CounterOpts{
Namespace: "grpc",
Subsystem: "server",
Name: "stream_messages_received",
Help: "The number of stream messages received.",
LabelNames: []string{"service", "method"},
StatsdFormat: "%{#fqname}.%{service}.%{method}",
}
streamMessagesSent = metrics.CounterOpts{
Namespace: "grpc",
Subsystem: "server",
Name: "stream_messages_sent",
Help: "The number of stream messages sent.",
LabelNames: []string{"service", "method"},
StatsdFormat: "%{#fqname}.%{service}.%{method}",
}
)
func NewUnaryMetrics(p metrics.Provider) *UnaryMetrics {
return &UnaryMetrics{
RequestDuration: p.NewHistogram(unaryRequestDuration),
RequestsReceived: p.NewCounter(unaryRequestsReceived),
RequestsCompleted: p.NewCounter(unaryRequestsCompleted),
}
}
func NewStreamMetrics(p metrics.Provider) *StreamMetrics {
return &StreamMetrics{
RequestDuration: p.NewHistogram(streamRequestDuration),
RequestsReceived: p.NewCounter(streamRequestsReceived),
RequestsCompleted: p.NewCounter(streamRequestsCompleted),
MessagesSent: p.NewCounter(streamMessagesSent),
MessagesReceived: p.NewCounter(streamMessagesReceived),
}
}