-
Notifications
You must be signed in to change notification settings - Fork 6
/
stats.go
419 lines (368 loc) · 9.68 KB
/
stats.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/*
* Copyright 2016 Xiaomi Corporation. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*
* Authors: Yu Bo <[email protected]>
*/
package govs
import "fmt"
const (
VS_CTL_S_SYNC = iota
VS_CTL_S_PENDING
VS_CTL_S_LAST
)
type Vs_stats_ifa struct {
Port_id int
Rx_packets int64
Rx_dropped int64
Tx_packets int64
Tx_dropped int64
}
type Vs_stats_io_entry struct {
Core_id int
Rx_nic_queues_port []int32
Rx_nic_queues_queue []int32
Rx_nic_queues_iters []int64
Rx_nic_queues_pkts []int64
Rx_rings_iters []int64
Rx_rings_pkts []int64
Rx_rings_drop_iters []int64
Rx_rings_drop_pkts []int64
Rx_rings_drop_count []int64
Tx_nic_ports_port []int32
Tx_nic_ports_queue []int32
Tx_nic_ports_iters []int64
Tx_nic_ports_pkts []int64
Tx_nic_ports_drop_iters []int64
Tx_nic_ports_drop_pkts []int64
Kni []Vs_stats_ifa
}
type Vs_stats_io_r struct {
Code int
Msg string
Io []Vs_stats_io_entry
}
/*
id kni_deq kni_err k_rx rx_d tx tx_d
*/
func (r Vs_stats_io_r) String() string {
if r.Code != 0 {
return fmt.Sprintf("%s:%s", Ecode(r.Code), r.Msg)
}
var ret string
for _, e := range r.Io {
ret += fmt.Sprintf("\n%-32s %-10s %10d\n", "#######", "core_id", e.Core_id)
for i, _ := range e.Rx_nic_queues_iters {
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d\n",
fmt.Sprintf("Rx_nic_port%d_queue%02d",
e.Rx_nic_queues_port[i], e.Rx_nic_queues_queue[i]),
"iters", e.Rx_nic_queues_iters[i],
"packets", e.Rx_nic_queues_pkts[i],
)
}
for i, _ := range e.Rx_rings_iters {
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d %-10s %10d %-10s %10d %-10s %10f\n",
fmt.Sprintf("rx_ring_worker%02d", i),
"iters", e.Rx_rings_iters[i],
"packets", e.Rx_rings_pkts[i],
"drop iters", e.Rx_rings_drop_iters[i],
"drop pkts", e.Rx_rings_drop_pkts[i],
"drop cnt", float64(e.Rx_rings_drop_count[i])/float64(e.Rx_rings_drop_iters[i]),
)
}
for i, _ := range e.Tx_nic_ports_iters {
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d %-10s %10d %-10s %10d\n",
fmt.Sprintf("tx_nic_port%d", e.Tx_nic_ports_port[i]),
"iters", e.Tx_nic_ports_iters[i],
"packets", e.Tx_nic_ports_pkts[i],
"drop iters", e.Tx_nic_ports_drop_iters[i],
"drop pkts", e.Tx_nic_ports_drop_pkts[i],
)
}
for _, kni := range e.Kni {
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d "+
"%-10s %10d %-10s %10d\n",
fmt.Sprintf("veth%d", kni.Port_id),
"rx_packets", kni.Rx_packets,
"rx_dropped", kni.Rx_dropped,
"tx_packets", kni.Tx_packets,
"tx_dropped", kni.Tx_dropped)
}
}
return ret
}
type Vs_stats_worker_entry struct {
Core_id int
Conns int64
Inpkts int64
Outpkts int64
Inbytes int64
Outbytes int64
Rings_in_iters []int64
Rings_in_pkts []int64
Rings_in_miss []int64
Rings_in_miss_count []int64
Rings_out_port []int32
Rings_out_iters []int64
Rings_out_pkts []int64
Rings_out_drop_iters []int64
Rings_out_drop_pkts []int64
Vs_drop []int64
}
type Vs_stats_worker_r struct {
Code int
Msg string
Worker []Vs_stats_worker_entry
}
func (r Vs_stats_worker_r) String() string {
if r.Code != 0 {
return fmt.Sprintf("%s:%s", Ecode(r.Code), r.Msg)
}
var ret string
for _, e := range r.Worker {
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d\n",
"", "Core_id", e.Core_id, "conns", e.Conns)
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d\n",
"In", "packets", e.Inpkts, "bytes", e.Inbytes)
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d\n",
"Out", "packets", e.Outpkts, "bytes", e.Outbytes)
for i, _ := range e.Rings_in_iters {
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d %-10s %10d %-10s %10d %-10s %10f\n",
fmt.Sprintf("rings_in_io%02d", i),
"iters", e.Rings_in_iters[i],
"packets", e.Rings_in_pkts[i],
"miss", e.Rings_in_miss[i],
"miss_count", e.Rings_in_miss_count[i],
"bsz", float64(e.Rings_in_miss_count[i])/float64(e.Rings_in_miss[i]),
)
}
for i, _ := range e.Rings_out_iters {
ret += fmt.Sprintf("%-32s %-10s %10d %-10s %10d %-10s %10d %-10s %10d\n",
fmt.Sprintf("rings_out_port%02d", e.Rings_out_port[i]),
"iters", e.Rings_out_iters[i],
"packets", e.Rings_out_pkts[i],
"drop iters", e.Rings_out_drop_iters[i],
"drop pkts", e.Rings_out_drop_pkts[i],
)
}
ret += "\n"
}
return ret
}
var estats_names = []string{
"core_id",
"fullnat_add_toa_ok",
"fullnat_add_toa_fail_len",
"fullnat_add_toa_head_full",
"fullnat_add_toa_fail_mem",
"fullnat_add_toa_fail_proto",
"fullnat_conn_reused",
"fullnat_conn_reused_close",
"fullnat_conn_reused_timewait",
"fullnat_conn_reused_finwait",
"fullnat_conn_reused_closewait",
"fullnat_conn_reused_lastack",
"fullnat_conn_reused_estab",
"synproxy_rs_error",
"synproxy_null_ack",
"synproxy_bad_ack",
"synproxy_ok_ack",
"synproxy_syn_cnt",
"synproxy_ackstorm",
"synproxy_synsend_qlen",
"synproxy_conn_reused",
"synproxy_conn_reused_close",
"synproxy_conn_reused_timewait",
"synproxy_conn_reused_finwait",
"synproxy_conn_reused_closewait",
"synproxy_conn_reused_lastack",
"defence_ip_frag_drop",
"defence_ip_frag_gather",
"defence_tcp_drop",
"defence_udp_drop",
"fast_xmit_reject",
"fast_xmit_pass",
"fast_xmit_skb_copy",
"fast_xmit_no_mac",
"fast_xmit_synproxy_save",
"fast_xmit_dev_lost",
"rst_in_syn_sent",
"rst_out_syn_sent",
"rst_in_established",
"rst_out_established",
"gro_pass",
"lro_reject",
"xmit_unexpected_mtu",
"conn_sched_unreach",
}
type Vs_estats_worker_r struct {
Code int
Msg string
Worker []map[string]int64
}
func (r Vs_estats_worker_r) String() (ret string) {
if r.Code != 0 {
return fmt.Sprintf("%s:%s", Ecode(r.Code), r.Msg)
}
if len(r.Worker) == 0 {
return fmt.Sprintf("No such object")
}
for _, name := range estats_names {
ret += fmt.Sprintf("%-32s", name)
for _, e := range r.Worker {
ret += fmt.Sprintf(" %10d", e[name])
}
ret += "\n"
}
return ret
}
type Vs_stats_dev_entry struct {
Port_id int
Ipackets int64
Opackets int64
Ibytes int64
Obytes int64
Imissed int64
Ierrors int64
Oerrors int64
Rx_nombuf int64
}
type Vs_stats_dev_r struct {
Code int
Msg string
Dev []Vs_stats_dev_entry
}
func (r Vs_stats_dev_r) String() string {
if r.Code != 0 {
return fmt.Sprintf("%s:%s", Ecode(r.Code), r.Msg)
}
ret := fmt.Sprintf("%-10s %10s %10s %10s %10s %10s %10s %10s %10s\n",
"port_id", "ipackets", "opackets", "ibytes", "obytes",
"imissed", "ierrors", "oerrors", "rx_nombuf")
for _, e := range r.Dev {
ret += fmt.Sprintf("%-10d %10d %10d %10d %10d %10d %10d %10d %10d\n",
e.Port_id, e.Ipackets, e.Opackets, e.Ibytes, e.Obytes,
e.Imissed, e.Ierrors, e.Oerrors, e.Rx_nombuf)
}
return ret
}
type Vs_stats_ctl_r struct {
Code int
Msg string
Num_services int
Seq int
Workers []struct {
Worker_id int
Num_services int
Seq int
State int
}
}
/*
id seq n_svc state
- 0 0 -
0 0 0 s
*/
func (r Vs_stats_ctl_r) String() string {
if r.Code != 0 {
return fmt.Sprintf("%s:%s", Ecode(r.Code), r.Msg)
}
ret := fmt.Sprintf("%-10s %10s %10s %10s\n",
"id", "seq", "n_svc", "state")
ret += fmt.Sprintf("%-10s %10d %10d %10c\n\n",
"-", r.Seq, r.Num_services, '-')
for _, e := range r.Workers {
ret += fmt.Sprintf("%-10d %10d %10d %10c\n",
e.Worker_id, e.Seq, e.Num_services, ctl_state_name(e.State))
}
return ret
}
type Vs_stats_mem_r struct {
Code int
Msg string
Size struct {
Mbuf int
Svc int
Rs int
Laddr int
Conn int
}
Available []struct {
Socket_id int
Mbuf int
Svc int
Rs int
Laddr int
Conn int
}
}
func (r Vs_stats_mem_r) String() string {
if r.Code != 0 {
return fmt.Sprintf("%s:%s", Ecode(r.Code), r.Msg)
}
ret := fmt.Sprintf("%-10s %10s %10s %10s %10s %10s\n",
"id", "mbuf", "svc", "rs", "laddr", "conn")
ret += fmt.Sprintf("%-10s %10d %10d %10d %10d %10d\n\n",
"max", r.Size.Mbuf, r.Size.Svc, r.Size.Rs, r.Size.Laddr, r.Size.Conn)
for _, e := range r.Available {
ret += fmt.Sprintf("%-10d %10d %10d %10d %10d %10d\n",
e.Socket_id,
r.Size.Mbuf-e.Mbuf,
r.Size.Svc-e.Svc,
r.Size.Rs-e.Rs,
r.Size.Laddr-e.Laddr,
r.Size.Conn-e.Conn)
}
return ret
}
type Vs_stats_q struct {
Type int
Id int
}
func ctl_state_name(s int) byte {
switch s {
case VS_CTL_S_SYNC:
return 's'
case VS_CTL_S_PENDING:
return 'p'
default:
return '-'
}
}
func Get_stats_io(id int) (*Vs_stats_io_r, error) {
args := Vs_stats_q{Type: VS_STATS_IO, Id: id}
reply := &Vs_stats_io_r{}
err := client.Call("stats", args, reply)
return reply, err
}
func Get_stats_worker(id int) (*Vs_stats_worker_r, error) {
args := Vs_stats_q{Type: VS_STATS_WORKER, Id: id}
reply := &Vs_stats_worker_r{}
err := client.Call("stats", args, reply)
return reply, err
}
func Get_estats_worker(id int) (*Vs_estats_worker_r, error) {
args := Vs_stats_q{Type: VS_ESTATS_WORKER, Id: id}
reply := &Vs_estats_worker_r{}
err := client.Call("stats", args, reply)
return reply, err
}
func Get_stats_dev(id int) (*Vs_stats_dev_r, error) {
args := Vs_stats_q{Type: VS_STATS_DEV, Id: id}
reply := &Vs_stats_dev_r{}
err := client.Call("stats", args, reply)
return reply, err
}
func Get_stats_ctl() (*Vs_stats_ctl_r, error) {
args := Vs_stats_q{Type: VS_STATS_CTL}
reply := &Vs_stats_ctl_r{}
err := client.Call("stats", args, reply)
return reply, err
}
func Get_stats_mem() (*Vs_stats_mem_r, error) {
args := Vs_stats_q{Type: VS_STATS_MEM}
reply := &Vs_stats_mem_r{}
err := client.Call("stats", args, reply)
return reply, err
}