@@ -24,6 +24,12 @@ import (
24
24
"strings"
25
25
)
26
26
27
+ var (
28
+ // isUDP is used to determine the type of network socket UDP or TCP.
29
+ // Further its value will be used to parse UDP-specific fields from /proc/net/udp{,6} files.
30
+ isUDP bool
31
+ )
32
+
27
33
const (
28
34
// readLimit is used by io.LimitReader while reading the content of the
29
35
// /proc/net/udp{,6} files. The number of lines inside such a file is dynamic
50
56
// UsedSockets shows the total number of parsed lines representing the
51
57
// number of used sockets.
52
58
UsedSockets uint64
59
+ // Drops shows the total number of dropped packets of all UPD sockets.
60
+ Drops * uint64
53
61
}
54
62
55
63
// netIPSocketLine represents the fields parsed from a single line
@@ -111,19 +119,28 @@ func newNetIPSocketSummary(file string) (*NetIPSocketSummary, error) {
111
119
defer f .Close ()
112
120
113
121
var netIPSocketSummary NetIPSocketSummary
122
+ var udpPacketDrops uint64
123
+
124
+ if strings .Contains (file , "udp" ) {
125
+ isUDP = true
126
+ }
114
127
115
128
lr := io .LimitReader (f , readLimit )
116
129
s := bufio .NewScanner (lr )
117
130
s .Scan () // skip first line with headers
118
131
for s .Scan () {
119
132
fields := strings .Fields (s .Text ())
120
- line , err := parseNetIPSocketLine (fields , false )
133
+ line , err := parseNetIPSocketLine (fields , isUDP )
121
134
if err != nil {
122
135
return nil , err
123
136
}
124
137
netIPSocketSummary .TxQueueLength += line .TxQueue
125
138
netIPSocketSummary .RxQueueLength += line .RxQueue
126
139
netIPSocketSummary .UsedSockets ++
140
+ if isUDP {
141
+ udpPacketDrops += * line .Drops
142
+ netIPSocketSummary .Drops = & udpPacketDrops
143
+ }
127
144
}
128
145
if err := s .Err (); err != nil {
129
146
return nil , err
0 commit comments