properly parse /proc/net/netstat
Costa Tsaousis (ktsaou) committed
Jan 21, 2017 at 19:40 UTC
bda105901dc47de2e3b35f08ec8ea9c6a1877fd9
1 file changed
+85
-57
src/proc_net_netstat.c
+85
-57
@@ -25,26 +25,64 @@ int do_proc_net_netstat(int update_every, usec_t dt) {
25
static procfile *ff = NULL;
26
27
ARL_BASE *arl_tcpext = NULL;
28
+ ARL_BASE *arl_ipext = NULL;
29
+
30
+ // --------------------------------------------------------------------
31
+ // IPv4
32
+
33
+ // IPv4 bandwidth
34
+ static unsigned long long ipext_InOctets = 0;
35
+ static unsigned long long ipext_OutOctets = 0;
36
+
37
+ // IPv4 input errors
38
+ static unsigned long long ipext_InNoRoutes = 0;
39
+ static unsigned long long ipext_InTruncatedPkts = 0;
40
+ static unsigned long long ipext_InCsumErrors = 0;
41
+
42
+ // IPv4 multicast bandwidth
43
+ static unsigned long long ipext_InMcastOctets = 0;
44
+ static unsigned long long ipext_OutMcastOctets = 0;
45
+
46
+ // IPv4 multicast packets
47
+ static unsigned long long ipext_InMcastPkts = 0;
48
+ static unsigned long long ipext_OutMcastPkts = 0;
49
29
- // Reordering
50
+ // IPv4 broadcast bandwidth
51
+ static unsigned long long ipext_InBcastOctets = 0;
52
+ static unsigned long long ipext_OutBcastOctets = 0;
53
+
54
+ // IPv4 broadcast packets
55
+ static unsigned long long ipext_InBcastPkts = 0;
56
+ static unsigned long long ipext_OutBcastPkts = 0;
57
+
58
+ // IPv4 ECN
59
+ static unsigned long long ipext_InNoECTPkts = 0;
60
+ static unsigned long long ipext_InECT1Pkts = 0;
61
+ static unsigned long long ipext_InECT0Pkts = 0;
62
+ static unsigned long long ipext_InCEPkts = 0;
63
+
64
+ // --------------------------------------------------------------------
65
+ // IPv4 TCP
66
+
67
+ // IPv4 TCP Reordering
68
static unsigned long long tcpext_TCPRenoReorder = 0;
69
static unsigned long long tcpext_TCPFACKReorder = 0;
70
static unsigned long long tcpext_TCPSACKReorder = 0;
71
static unsigned long long tcpext_TCPTSReorder = 0;
72
35
- // SYN Cookies
73
+ // IPv4 TCP SYN Cookies
74
static unsigned long long tcpext_SyncookiesSent = 0;
75
static unsigned long long tcpext_SyncookiesRecv = 0;
76
static unsigned long long tcpext_SyncookiesFailed = 0;
77
40
- // Out Of Order Queue
78
+ // IPv4 TCP Out Of Order Queue
79
// http://www.spinics.net/lists/netdev/msg204696.html
80
static unsigned long long tcpext_TCPOFOQueue = 0; // Number of packets queued in OFO queue
81
static unsigned long long tcpext_TCPOFODrop = 0; // Number of packets meant to be queued in OFO but dropped because socket rcvbuf limit hit.
82
static unsigned long long tcpext_TCPOFOMerge = 0; // Number of packets in OFO that were merged with other packets.
83
static unsigned long long tcpext_OfoPruned = 0; // packets dropped from out-of-order queue because of socket buffer overrun
84
47
- // connection resets
85
+ // IPv4 TCP connection resets
86
// https://github.com/ecki/net-tools/blob/bd8bceaed2311651710331a7f8990c3e31be9840/statistics.c
87
static unsigned long long tcpext_TCPAbortOnData = 0; // connections reset due to unexpected data
88
static unsigned long long tcpext_TCPAbortOnClose = 0; // connections reset due to early user close
@@ -53,28 +91,13 @@ int do_proc_net_netstat(int update_every, usec_t dt) {
91
static unsigned long long tcpext_TCPAbortOnLinger = 0; // connections aborted after user close in linger timeout
92
static unsigned long long tcpext_TCPAbortFailed = 0; // times unable to send RST due to no memory
93
94
+ // IPv4 TCP memory pressures
95
static unsigned long long tcpext_TCPMemoryPressures = 0;
96
58
- ARL_BASE *arl_ipext = NULL;
59
- static unsigned long long ipext_InNoRoutes = 0;
60
- static unsigned long long ipext_InTruncatedPkts = 0;
61
- static unsigned long long ipext_InMcastPkts = 0;
62
- static unsigned long long ipext_OutMcastPkts = 0;
63
- static unsigned long long ipext_InBcastPkts = 0;
64
- static unsigned long long ipext_OutBcastPkts = 0;
65
- static unsigned long long ipext_InOctets = 0;
66
- static unsigned long long ipext_OutOctets = 0;
67
- static unsigned long long ipext_InMcastOctets = 0;
68
- static unsigned long long ipext_OutMcastOctets = 0;
69
- static unsigned long long ipext_InBcastOctets = 0;
70
- static unsigned long long ipext_OutBcastOctets = 0;
71
- static unsigned long long ipext_InCsumErrors = 0;
72
- static unsigned long long ipext_InNoECTPkts = 0;
73
- static unsigned long long ipext_InECT1Pkts = 0;
74
- static unsigned long long ipext_InECT0Pkts = 0;
75
- static unsigned long long ipext_InCEPkts = 0;
76
-
97
if(unlikely(!arl_ipext)) {
98
+ hash_ipext = simple_hash("IpExt");
99
+ hash_tcpext = simple_hash("TcpExt");
100
+
101
do_bandwidth = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "bandwidth", CONFIG_ONDEMAND_ONDEMAND);
102
do_inerrors = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "input errors", CONFIG_ONDEMAND_ONDEMAND);
103
do_mcast = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "multicast bandwidth", CONFIG_ONDEMAND_ONDEMAND);
@@ -89,42 +112,11 @@ int do_proc_net_netstat(int update_every, usec_t dt) {
112
do_tcpext_connaborts = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "TCP connection aborts", CONFIG_ONDEMAND_ONDEMAND);
113
do_tcpext_memory = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "TCP memory pressures", CONFIG_ONDEMAND_ONDEMAND);
114
115
+ arl_ipext = arl_create(NULL, 60);
116
arl_tcpext = arl_create(NULL, 60);
117
94
- if(do_tcpext_reorder != CONFIG_ONDEMAND_NO) {
95
- arl_expect(arl_tcpext, "TCPFACKReorder", &tcpext_TCPFACKReorder);
96
- arl_expect(arl_tcpext, "TCPSACKReorder", &tcpext_TCPSACKReorder);
97
- arl_expect(arl_tcpext, "TCPRenoReorder", &tcpext_TCPRenoReorder);
98
- arl_expect(arl_tcpext, "TCPTSReorder", &tcpext_TCPTSReorder);
99
- }
100
-
101
- if(do_tcpext_syscookies != CONFIG_ONDEMAND_NO) {
102
- arl_expect(arl_tcpext, "SyncookiesSent", &tcpext_SyncookiesSent);
103
- arl_expect(arl_tcpext, "SyncookiesRecv", &tcpext_SyncookiesRecv);
104
- arl_expect(arl_tcpext, "SyncookiesFailed", &tcpext_SyncookiesFailed);
105
- }
106
-
107
- if(do_tcpext_ofo != CONFIG_ONDEMAND_NO) {
108
- arl_expect(arl_tcpext, "TCPOFOQueue", &tcpext_TCPOFOQueue);
109
- arl_expect(arl_tcpext, "TCPOFODrop", &tcpext_TCPOFODrop);
110
- arl_expect(arl_tcpext, "TCPOFOMerge", &tcpext_TCPOFOMerge);
111
- arl_expect(arl_tcpext, "OfoPruned", &tcpext_OfoPruned);
112
- }
113
-
114
- if(do_tcpext_connaborts != CONFIG_ONDEMAND_NO) {
115
- arl_expect(arl_tcpext, "TCPAbortOnData", &tcpext_TCPAbortOnData);
116
- arl_expect(arl_tcpext, "TCPAbortOnClose", &tcpext_TCPAbortOnClose);
117
- arl_expect(arl_tcpext, "TCPAbortOnMemory", &tcpext_TCPAbortOnMemory);
118
- arl_expect(arl_tcpext, "TCPAbortOnTimeout", &tcpext_TCPAbortOnTimeout);
119
- arl_expect(arl_tcpext, "TCPAbortOnLinger", &tcpext_TCPAbortOnLinger);
120
- arl_expect(arl_tcpext, "TCPAbortFailed", &tcpext_TCPAbortFailed);
121
- }
122
-
123
- if(do_tcpext_memory != CONFIG_ONDEMAND_NO) {
124
- arl_expect(arl_tcpext, "TCPMemoryPressures", &tcpext_TCPMemoryPressures);
125
- }
126
-
127
- arl_ipext = arl_create(NULL, 60);
118
+ // --------------------------------------------------------------------
119
+ // IPv4
120
121
if(do_bandwidth != CONFIG_ONDEMAND_NO) {
122
arl_expect(arl_ipext, "InOctets", &ipext_InOctets);
@@ -163,6 +155,42 @@ int do_proc_net_netstat(int update_every, usec_t dt) {
155
arl_expect(arl_ipext, "InECT0Pkts", &ipext_InECT0Pkts);
156
arl_expect(arl_ipext, "InCEPkts", &ipext_InCEPkts);
157
}
158
+
159
+ // --------------------------------------------------------------------
160
+ // IPv4 TCP
161
+
162
+ if(do_tcpext_reorder != CONFIG_ONDEMAND_NO) {
163
+ arl_expect(arl_tcpext, "TCPFACKReorder", &tcpext_TCPFACKReorder);
164
+ arl_expect(arl_tcpext, "TCPSACKReorder", &tcpext_TCPSACKReorder);
165
+ arl_expect(arl_tcpext, "TCPRenoReorder", &tcpext_TCPRenoReorder);
166
+ arl_expect(arl_tcpext, "TCPTSReorder", &tcpext_TCPTSReorder);
167
+ }
168
+
169
+ if(do_tcpext_syscookies != CONFIG_ONDEMAND_NO) {
170
+ arl_expect(arl_tcpext, "SyncookiesSent", &tcpext_SyncookiesSent);
171
+ arl_expect(arl_tcpext, "SyncookiesRecv", &tcpext_SyncookiesRecv);
172
+ arl_expect(arl_tcpext, "SyncookiesFailed", &tcpext_SyncookiesFailed);
173
+ }
174
+
175
+ if(do_tcpext_ofo != CONFIG_ONDEMAND_NO) {
176
+ arl_expect(arl_tcpext, "TCPOFOQueue", &tcpext_TCPOFOQueue);
177
+ arl_expect(arl_tcpext, "TCPOFODrop", &tcpext_TCPOFODrop);
178
+ arl_expect(arl_tcpext, "TCPOFOMerge", &tcpext_TCPOFOMerge);
179
+ arl_expect(arl_tcpext, "OfoPruned", &tcpext_OfoPruned);
180
+ }
181
+
182
+ if(do_tcpext_connaborts != CONFIG_ONDEMAND_NO) {
183
+ arl_expect(arl_tcpext, "TCPAbortOnData", &tcpext_TCPAbortOnData);
184
+ arl_expect(arl_tcpext, "TCPAbortOnClose", &tcpext_TCPAbortOnClose);
185
+ arl_expect(arl_tcpext, "TCPAbortOnMemory", &tcpext_TCPAbortOnMemory);
186
+ arl_expect(arl_tcpext, "TCPAbortOnTimeout", &tcpext_TCPAbortOnTimeout);
187
+ arl_expect(arl_tcpext, "TCPAbortOnLinger", &tcpext_TCPAbortOnLinger);
188
+ arl_expect(arl_tcpext, "TCPAbortFailed", &tcpext_TCPAbortFailed);
189
+ }
190
+
191
+ if(do_tcpext_memory != CONFIG_ONDEMAND_NO) {
192
+ arl_expect(arl_tcpext, "TCPMemoryPressures", &tcpext_TCPMemoryPressures);
193
+ }
194
}
195
196
if(unlikely(!ff)) {