forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
95 lines (89 loc) · 3.62 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 SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package metrics
import "github.com/VRamakrishna/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/metrics"
var (
// for now, only channel clients require metrics tracking. TODO: update to generalize metrics for other client types if needed.
queriesReceived = metrics.CounterOpts{
Namespace: "channel",
Name: "queries_received",
Help: "The number of channel client queries received.",
LabelNames: []string{"chaincode", "Fcn"},
StatsdFormat: "%{#fqname}.%{type}.%{channel}.%{query}",
}
queriesFailed = metrics.CounterOpts{
Namespace: "channel",
Name: "queries_failed",
Help: "The number of channel client queries that failed (timeouts excluded).",
LabelNames: []string{"chaincode", "Fcn", "fail"},
StatsdFormat: "%{#fqname}.%{type}.%{channel}.%{query}.%{fail}",
}
queryTimeouts = metrics.CounterOpts{
Namespace: "channel",
Name: "query_timeouts",
Help: "The number of channel queries that have failed due to time out.",
LabelNames: []string{"chaincode", "Fcn", "fail"},
StatsdFormat: "%{#fqname}.%{type}.%{channel}.%{query}.%{timeout}",
}
queryDuration = metrics.HistogramOpts{
Namespace: "channel",
Name: "query_duration",
Help: "The time to complete channel client query.",
LabelNames: []string{"chaincode", "Fcn"},
StatsdFormat: "%{#fqname}.%{type}.%{channel}.%{query}",
}
executionsReceived = metrics.CounterOpts{
Namespace: "channel",
Name: "executions_received",
Help: "The number of channel client executions received.",
LabelNames: []string{"chaincode", "Fcn"},
StatsdFormat: "%{#fqname}.%{type}.%{channel}.%{execute}",
}
executionsFailed = metrics.CounterOpts{
Namespace: "channel",
Name: "executions_failed",
Help: "The number of channel client executions that failed (timeouts excluded).",
LabelNames: []string{"chaincode", "Fcn", "fail"},
StatsdFormat: "%{#fqname}.%{type}.%{channel}.%{execute}.%{fail}",
}
executionTimeouts = metrics.CounterOpts{
Namespace: "channel",
Name: "execution_timeouts",
Help: "The number of channel executions that have failed due to time out.",
LabelNames: []string{"chaincode", "Fcn", "fail"},
StatsdFormat: "%{#fqname}.%{type}.%{channel}.%{execute}.%{timeout}",
}
executionDuration = metrics.HistogramOpts{
Namespace: "channel",
Name: "execution_duration",
Help: "The time to complete channel client execution.",
LabelNames: []string{"chaincode", "Fcn"},
StatsdFormat: "%{#fqname}.%{type}.%{channel}.%{execution}",
}
)
// ClientMetrics contains the metrics used in the (channel) client
type ClientMetrics struct {
QueriesReceived metrics.Counter
QueriesFailed metrics.Counter
QueryDuration metrics.Histogram
QueryTimeouts metrics.Counter
ExecutionsReceived metrics.Counter
ExecutionsFailed metrics.Counter
ExecutionDuration metrics.Histogram
ExecutionTimeouts metrics.Counter
}
// NewClientMetrics builds a new instance of ClientMetrics
func NewClientMetrics(p metrics.Provider) *ClientMetrics {
return &ClientMetrics{
QueriesReceived: p.NewCounter(queriesReceived),
QueriesFailed: p.NewCounter(queriesFailed),
QueryDuration: p.NewHistogram(queryDuration),
QueryTimeouts: p.NewCounter(queryTimeouts),
ExecutionsReceived: p.NewCounter(executionsReceived),
ExecutionsFailed: p.NewCounter(executionsFailed),
ExecutionDuration: p.NewHistogram(executionDuration),
ExecutionTimeouts: p.NewCounter(executionTimeouts),
}
}