-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
168 lines (148 loc) · 5.93 KB
/
client.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
type ClientConfig struct {
MessageInflightTimeBuckets []float64
ReceivedMessageSizeBuckets []float64
SentMessageSizeBuckets []float64
MessageProcessingTimeBuckets []float64
SendSyncResponseTimeBuckets []float64
SendTimeBuckets []float64
}
func DefaultClientConfig() ClientConfig {
return ClientConfig{
MessageInflightTimeBuckets: prometheus.DefBuckets,
ReceivedMessageSizeBuckets: defBucketsForSizeBytes,
SentMessageSizeBuckets: defBucketsForSizeBytes,
MessageProcessingTimeBuckets: prometheus.DefBuckets,
SendSyncResponseTimeBuckets: prometheus.DefBuckets,
SendTimeBuckets: prometheus.DefBuckets,
}
}
type ClientMetrics struct {
MessageInflightTime *prometheus.HistogramVec
MessageReceivedSize *prometheus.HistogramVec
MessageSentSize *prometheus.HistogramVec
MessageProcessingTime *prometheus.HistogramVec
MessageSentSyncResponseTime *prometheus.HistogramVec
MessageSentTime *prometheus.HistogramVec
CurrentStatus prometheus.Gauge
ConcurrentWorkers prometheus.Gauge
ConfigMaxConcurrency prometheus.Gauge
BroadcastCmdCount *prometheus.CounterVec
SubscribeCmdCount *prometheus.CounterVec
UnsubscribeCmdCount *prometheus.CounterVec
PublishCmdCount *prometheus.CounterVec
Errors prometheus.Counter
}
func NewClientMetrics(c ClientConfig) *ClientMetrics {
return &ClientMetrics{
MessageInflightTime: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "message_received_inflight_duration_seconds",
Help: "The time the message spent over the wire till received",
Buckets: c.MessageInflightTimeBuckets,
}, []string{"kind"}),
MessageReceivedSize: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "message_received_size_bytes",
Help: "The size of the received messages in bytes",
Buckets: c.ReceivedMessageSizeBuckets,
}, []string{"kind"}),
MessageSentSize: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "message_sent_size_bytes",
Help: "The size of the sent messages in bytes",
Buckets: c.SentMessageSizeBuckets,
}, []string{"kind"}),
MessageSentTime: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "message_sent_duration_seconds",
Help: "The time spent in during asynchronous message sending operation (buffer)",
Buckets: c.SendTimeBuckets,
}, []string{"kind"}),
MessageProcessingTime: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "message_processing_duration_seconds",
Help: "The time spent in message handler execution",
Buckets: c.MessageProcessingTimeBuckets,
}, []string{"kind"}),
MessageSentSyncResponseTime: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "message_sent_sync_duration_seconds",
Help: "The time spent in a synchronous message sending operation",
Buckets: c.SendSyncResponseTimeBuckets,
}, []string{"kind"}),
CurrentStatus: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "status",
Help: "The current status of the client (0 => New, 1 => Running, 2=> Closing, 3 => closed)",
}),
ConcurrentWorkers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "concurrent_workers",
Help: "The current number of running workers in the client",
}),
ConfigMaxConcurrency: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "config_max_concurrency",
Help: "The configured maximum number of parallel workers in the client",
}),
BroadcastCmdCount: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "broadcast_cmd_sent_total",
Help: "The number of broadcast commands sent by the client to the server.",
}, []string{"message"}),
SubscribeCmdCount: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "goomerang",
Subsystem: "client_pubsub",
Name: "subscribe_cmd_sent_total",
Help: "The number of subscribe commands sent by the client to the server.",
}, []string{"topic"}),
PublishCmdCount: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "goomerang",
Subsystem: "client_pubsub",
Name: "publish_cmd_sent_total",
Help: "The number of publish commands sent by the client to the server.",
}, []string{"topic", "message"}),
UnsubscribeCmdCount: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "goomerang",
Subsystem: "client_pubsub",
Name: "unsubscribe_cmd_sent_total",
Help: "The number of unsubscribe commands sent by the client to the server.",
}, []string{"topic"}),
Errors: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "goomerang",
Subsystem: "client",
Name: "errors_total",
Help: "The errors happened in client",
}),
}
}
func (m *ClientMetrics) Register(r prometheus.Registerer) {
r.MustRegister(m.MessageInflightTime)
r.MustRegister(m.MessageReceivedSize)
r.MustRegister(m.MessageSentSize)
r.MustRegister(m.MessageSentTime)
r.MustRegister(m.MessageProcessingTime)
r.MustRegister(m.MessageSentSyncResponseTime)
r.MustRegister(m.CurrentStatus)
r.MustRegister(m.ConcurrentWorkers)
r.MustRegister(m.ConfigMaxConcurrency)
r.MustRegister(m.BroadcastCmdCount)
r.MustRegister(m.SubscribeCmdCount)
r.MustRegister(m.PublishCmdCount)
r.MustRegister(m.UnsubscribeCmdCount)
r.MustRegister(m.Errors)
}