forked from florianl/go-conntrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattributeStats.go
106 lines (96 loc) · 2.18 KB
/
attributeStats.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
package conntrack
import (
"encoding/binary"
"log"
"github.com/mdlayher/netlink"
)
const (
ctaStatsUnspec = iota
ctaStatsSearched /* no longer used */
ctaStatsFound
ctaStatsNew /* no longer used */
ctaStatsInvalid
ctaStatsIgnore
ctaStatsDelete /* no longer used */
ctaStatsDeleteList /* no longer used */
ctaStatsInsert
ctaStatsInsertFailed
ctaStatsDrop
ctaStatsEarlyDrop
ctaStatsError
ctaStatsSearchRestart
)
const (
ctaStatsExpUnspec = iota
ctaStatsExpNew
ctaStatsExpCreate
ctaStatsExpDelete
)
func extractCPUStats(s *CPUStat, logger *log.Logger, data []byte) error {
ad, err := netlink.NewAttributeDecoder(data)
if err != nil {
return err
}
// the CPU ID does not have its own attribute
s.ID = binary.BigEndian.Uint32(data[0:4])
ad.ByteOrder = binary.BigEndian
for ad.Next() {
switch ad.Type() {
case ctaStatsFound:
tmp := ad.Uint32()
s.Found = &tmp
case ctaStatsInvalid:
tmp := ad.Uint32()
s.Invalid = &tmp
case ctaStatsIgnore:
tmp := ad.Uint32()
s.Ignore = &tmp
case ctaStatsInsert:
tmp := ad.Uint32()
s.Insert = &tmp
case ctaStatsInsertFailed:
tmp := ad.Uint32()
s.InsertFailed = &tmp
case ctaStatsDrop:
tmp := ad.Uint32()
s.Drop = &tmp
case ctaStatsEarlyDrop:
tmp := ad.Uint32()
s.EarlyDrop = &tmp
case ctaStatsError:
tmp := ad.Uint32()
s.Error = &tmp
case ctaStatsSearchRestart:
tmp := ad.Uint32()
s.SearchRestart = &tmp
default:
logger.Printf("extractCPUStats()): %d | %d\t %v", ad.Type(), ad.Type()&0xFF, ad.Bytes())
}
}
return ad.Err()
}
func extractExpCPUStats(s *CPUStat, logger *log.Logger, data []byte) error {
ad, err := netlink.NewAttributeDecoder(data)
if err != nil {
return err
}
// the CPU ID does not have its own attribute
s.ID = binary.BigEndian.Uint32(data[0:4])
ad.ByteOrder = binary.BigEndian
for ad.Next() {
switch ad.Type() {
case ctaStatsExpNew:
tmp := ad.Uint32()
s.ExpNew = &tmp
case ctaStatsExpCreate:
tmp := ad.Uint32()
s.ExpCreate = &tmp
case ctaStatsExpDelete:
tmp := ad.Uint32()
s.ExpDelete = &tmp
default:
logger.Printf("extractExpCPUStats()): %d | %d\t %v", ad.Type(), ad.Type()&0xFF, ad.Bytes())
}
}
return ad.Err()
}