-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
149 lines (127 loc) · 4.96 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package cluster
import (
"time"
"github.com/hyperledger/fabric/common/metrics"
)
var (
EgressQueueLengthOpts = metrics.GaugeOpts{
Namespace: "cluster",
Subsystem: "comm",
Name: "egress_queue_length",
Help: "Length of the egress queue.",
LabelNames: []string{"host", "msg_type", "channel"},
StatsdFormat: "%{#fqname}.%{host}.%{msg_type}.%{channel}",
}
EgressQueueCapacityOpts = metrics.GaugeOpts{
Namespace: "cluster",
Subsystem: "comm",
Name: "egress_queue_capacity",
Help: "Capacity of the egress queue.",
LabelNames: []string{"host", "msg_type", "channel"},
StatsdFormat: "%{#fqname}.%{host}.%{msg_type}.%{channel}",
}
EgressWorkersOpts = metrics.GaugeOpts{
Namespace: "cluster",
Subsystem: "comm",
Name: "egress_queue_workers",
Help: "Count of egress queue workers.",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
}
IngressStreamsCountOpts = metrics.GaugeOpts{
Namespace: "cluster",
Subsystem: "comm",
Name: "ingress_stream_count",
Help: "Count of streams from other nodes.",
StatsdFormat: "%{#fqname}",
}
EgressStreamsCountOpts = metrics.GaugeOpts{
Namespace: "cluster",
Subsystem: "comm",
Name: "egress_stream_count",
Help: "Count of streams to other nodes.",
LabelNames: []string{"channel"},
StatsdFormat: "%{#fqname}.%{channel}",
}
EgressTLSConnectionCountOpts = metrics.GaugeOpts{
Namespace: "cluster",
Subsystem: "comm",
Name: "egress_tls_connection_count",
Help: "Count of TLS connections to other nodes.",
StatsdFormat: "%{#fqname}",
}
MessageSendTimeOpts = metrics.HistogramOpts{
Namespace: "cluster",
Subsystem: "comm",
Name: "msg_send_time",
Help: "The time it takes to send a message in seconds.",
LabelNames: []string{"host", "channel"},
StatsdFormat: "%{#fqname}.%{host}.%{channel}",
}
MessagesDroppedCountOpts = metrics.CounterOpts{
Namespace: "cluster",
Subsystem: "comm",
Name: "msg_dropped_count",
Help: "Count of messages dropped.",
LabelNames: []string{"host", "channel"},
StatsdFormat: "%{#fqname}.%{host}.%{channel}",
}
)
// Metrics defines the metrics for the cluster.
type Metrics struct {
EgressQueueLength metrics.Gauge
EgressQueueCapacity metrics.Gauge
EgressWorkerCount metrics.Gauge
IngressStreamsCount metrics.Gauge
EgressStreamsCount metrics.Gauge
EgressTLSConnectionCount metrics.Gauge
MessageSendTime metrics.Histogram
MessagesDroppedCount metrics.Counter
}
// A MetricsProvider is an abstraction for a metrics provider. It is a factory for
// Counter, Gauge, and Histogram meters.
type MetricsProvider interface {
// NewCounter creates a new instance of a Counter.
NewCounter(opts metrics.CounterOpts) metrics.Counter
// NewGauge creates a new instance of a Gauge.
NewGauge(opts metrics.GaugeOpts) metrics.Gauge
// NewHistogram creates a new instance of a Histogram.
NewHistogram(opts metrics.HistogramOpts) metrics.Histogram
}
//go:generate mockery -dir . -name MetricsProvider -case underscore -output ./mocks/
// NewMetrics initializes new metrics for the cluster infrastructure.
func NewMetrics(provider MetricsProvider) *Metrics {
return &Metrics{
EgressQueueLength: provider.NewGauge(EgressQueueLengthOpts),
EgressQueueCapacity: provider.NewGauge(EgressQueueCapacityOpts),
EgressStreamsCount: provider.NewGauge(EgressStreamsCountOpts),
EgressTLSConnectionCount: provider.NewGauge(EgressTLSConnectionCountOpts),
EgressWorkerCount: provider.NewGauge(EgressWorkersOpts),
IngressStreamsCount: provider.NewGauge(IngressStreamsCountOpts),
MessagesDroppedCount: provider.NewCounter(MessagesDroppedCountOpts),
MessageSendTime: provider.NewHistogram(MessageSendTimeOpts),
}
}
func (m *Metrics) reportMessagesDropped(host, channel string) {
m.MessagesDroppedCount.With("host", host, "channel", channel).Add(1)
}
func (m *Metrics) reportQueueOccupancy(host string, msgType string, channel string, length, capacity int) {
m.EgressQueueLength.With("host", host, "msg_type", msgType, "channel", channel).Set(float64(length))
m.EgressQueueCapacity.With("host", host, "msg_type", msgType, "channel", channel).Set(float64(capacity))
}
func (m *Metrics) reportWorkerCount(channel string, count uint32) {
m.EgressWorkerCount.With("channel", channel).Set(float64(count))
}
func (m *Metrics) reportMsgSendTime(host string, channel string, duration time.Duration) {
m.MessageSendTime.With("host", host, "channel", channel).Observe(float64(duration.Seconds()))
}
func (m *Metrics) reportEgressStreamCount(channel string, count uint32) {
m.EgressStreamsCount.With("channel", channel).Set(float64(count))
}
func (m *Metrics) reportStreamCount(count uint32) {
m.IngressStreamsCount.Set(float64(count))
}