added /proc/net/sockstat6
Costa Tsaousis (ktsaou) committed
Nov 8, 2017 at 00:49 UTC
53805b04e578053a946dd678164904c2991f30ff
7 files changed
+298
-26
CMakeLists.txt
+1
@@ -50,6 +50,7 @@ set(NETDATA_LINUX_FILES
50
src/proc_net_snmp.c
51
src/proc_net_snmp6.c
52
src/proc_net_sockstat.c
53
+ src/proc_net_sockstat6.c
54
src/proc_net_softnet_stat.c
55
src/proc_net_stat_conntrack.c
56
src/proc_net_stat_synproxy.c
src/Makefile.am
+1
@@ -196,6 +196,7 @@ netdata_SOURCES += \
196
proc_net_snmp.c \
197
proc_net_snmp6.c \
198
proc_net_sockstat.c \
199
+ proc_net_sockstat6.c \
200
proc_net_softnet_stat.c \
201
proc_net_stat_conntrack.c \
202
proc_net_stat_synproxy.c \
src/plugin_proc.c
+1
@@ -33,6 +33,7 @@ static struct proc_module {
33
// network metrics
34
{ .name = "/proc/net/dev", .dim = "netdev", .func = do_proc_net_dev },
35
{ .name = "/proc/net/sockstat", .dim = "sockstat", .func = do_proc_net_sockstat },
36
+ { .name = "/proc/net/sockstat6", .dim = "sockstat6", .func = do_proc_net_sockstat6 },
37
{ .name = "/proc/net/netstat", .dim = "netstat", .func = do_proc_net_netstat }, // this has to be before /proc/net/snmp, because there is a shared metric
38
{ .name = "/proc/net/snmp", .dim = "snmp", .func = do_proc_net_snmp },
39
{ .name = "/proc/net/snmp6", .dim = "snmp6", .func = do_proc_net_snmp6 },
src/plugin_proc.h
+1
@@ -27,6 +27,7 @@ extern int do_proc_sys_devices_system_edac_mc(int update_every, usec_t dt);
27
extern int do_proc_sys_devices_system_node(int update_every, usec_t dt);
28
extern int do_proc_spl_kstat_zfs_arcstats(int update_every, usec_t dt);
29
extern int do_proc_net_sockstat(int update_every, usec_t dt);
30
+extern int do_proc_net_sockstat6(int update_every, usec_t dt);
31
32
extern int get_numa_node_count(void);
33
src/proc_net_snmp6.c
+21
-21
@@ -360,13 +360,13 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
360
RRD_TYPE_NET_SNMP6
361
, "fragsout"
362
, NULL
363
- , "fragments"
363
+ , "fragments6"
364
, NULL
365
, "IPv6 Fragments Sent"
366
, "packets/s"
367
, "proc"
368
, "net/snmp6"
369
- , 3010
369
+ , 3011
370
, update_every
371
, RRDSET_TYPE_LINE
372
);
@@ -406,13 +406,13 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
406
RRD_TYPE_NET_SNMP6
407
, "fragsin"
408
, NULL
409
- , "fragments"
409
+ , "fragments6"
410
, NULL
411
, "IPv6 Fragments Reassembly"
412
, "packets/s"
413
, "proc"
414
, "net/snmp6"
415
- , 3011
415
+ , 3012
416
, update_every
417
, RRDSET_TYPE_LINE);
418
rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
@@ -510,7 +510,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
510
RRD_TYPE_NET_SNMP6
511
, "udppackets"
512
, NULL
513
- , "udp"
513
+ , "udp6"
514
, NULL
515
, "IPv6 UDP Packets"
516
, "packets/s"
@@ -556,7 +556,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
556
RRD_TYPE_NET_SNMP6
557
, "udperrors"
558
, NULL
559
- , "udp"
559
+ , "udp6"
560
, NULL
561
, "IPv6 UDP Errors"
562
, "events/s"
@@ -599,13 +599,13 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
599
RRD_TYPE_NET_SNMP6
600
, "udplitepackets"
601
, NULL
602
- , "udplite"
602
+ , "udplite6"
603
, NULL
604
, "IPv6 UDPlite Packets"
605
, "packets/s"
606
, "proc"
607
, "net/snmp6"
608
- , 3601
608
+ , 3602
609
, update_every
610
, RRDSET_TYPE_LINE
611
);
@@ -644,7 +644,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
644
RRD_TYPE_NET_SNMP6
645
, "udpliteerrors"
646
, NULL
647
- , "udplite"
647
+ , "udplite6"
648
, NULL
649
, "IPv6 UDP Lite Errors"
650
, "events/s"
@@ -685,7 +685,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
685
RRD_TYPE_NET_SNMP6
686
, "mcast"
687
, NULL
688
- , "multicast"
688
+ , "multicast6"
689
, NULL
690
, "IPv6 Multicast Bandwidth"
691
, "kilobits/s"
@@ -720,7 +720,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
720
RRD_TYPE_NET_SNMP6
721
, "bcast"
722
, NULL
723
- , "broadcast"
723
+ , "broadcast6"
724
, NULL
725
, "IPv6 Broadcast Bandwidth"
726
, "kilobits/s"
@@ -755,7 +755,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
755
RRD_TYPE_NET_SNMP6
756
, "mcastpkts"
757
, NULL
758
- , "multicast"
758
+ , "multicast6"
759
, NULL
760
, "IPv6 Multicast Packets"
761
, "packets/s"
@@ -790,7 +790,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
790
RRD_TYPE_NET_SNMP6
791
, "icmp"
792
, NULL
793
- , "icmp"
793
+ , "icmp6"
794
, NULL
795
, "IPv6 ICMP Messages"
796
, "messages/s"
@@ -824,7 +824,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
824
RRD_TYPE_NET_SNMP6
825
, "icmpredir"
826
, NULL
827
- , "icmp"
827
+ , "icmp6"
828
, NULL
829
, "IPv6 ICMP Redirects"
830
, "redirects/s"
@@ -880,7 +880,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
880
RRD_TYPE_NET_SNMP6
881
, "icmperrors"
882
, NULL
883
- , "icmp"
883
+ , "icmp6"
884
, NULL
885
, "IPv6 ICMP Errors"
886
, "errors/s"
@@ -940,7 +940,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
940
RRD_TYPE_NET_SNMP6
941
, "icmpechos"
942
, NULL
943
- , "icmp"
943
+ , "icmp6"
944
, NULL
945
, "IPv6 ICMP Echo"
946
, "messages/s"
@@ -990,7 +990,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
990
RRD_TYPE_NET_SNMP6
991
, "groupmemb"
992
, NULL
993
- , "icmp"
993
+ , "icmp6"
994
, NULL
995
, "IPv6 ICMP Group Membership"
996
, "messages/s"
@@ -1039,7 +1039,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
1039
RRD_TYPE_NET_SNMP6
1040
, "icmprouter"
1041
, NULL
1042
- , "icmp"
1042
+ , "icmp6"
1043
, NULL
1044
, "IPv6 Router Messages"
1045
, "messages/s"
@@ -1085,7 +1085,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
1085
RRD_TYPE_NET_SNMP6
1086
, "icmpneighbor"
1087
, NULL
1088
- , "icmp"
1088
+ , "icmp6"
1089
, NULL
1090
, "IPv6 Neighbor Messages"
1091
, "messages/s"
@@ -1123,7 +1123,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
1123
RRD_TYPE_NET_SNMP6
1124
, "icmpmldv2"
1125
, NULL
1126
- , "icmp"
1126
+ , "icmp6"
1127
, NULL
1128
, "IPv6 ICMP MLDv2 Reports"
1129
, "reports/s"
@@ -1177,7 +1177,7 @@ int do_proc_net_snmp6(int update_every, usec_t dt) {
1177
RRD_TYPE_NET_SNMP6
1178
, "icmptypes"
1179
, NULL
1180
- , "icmp"
1180
+ , "icmp6"
1181
, NULL
1182
, "IPv6 ICMP Types"
1183
, "messages/s"
src/proc_net_sockstat.c
+4
-5
@@ -1,7 +1,5 @@
1
#include "common.h"
2
3
-#define RRD_TYPE_NET_SNMP "ipv4"
4
-
3
static struct proc_net_sockstat {
4
kernel_uint_t sockets_used;
5
@@ -111,9 +109,9 @@ int do_proc_net_sockstat(int update_every, usec_t dt) {
109
110
static int do_sockets = -1, do_tcp_sockets = -1, do_tcp_mem = -1, do_udp_sockets = -1, do_udp_mem = -1, do_udplite_sockets = -1, do_raw_sockets = -1, do_frag_sockets = -1, do_frag_mem = -1;
111
114
- static char *keys[6] = { NULL };
115
- static uint32_t hashes[6] = { 0 };
116
- static ARL_BASE *bases[6] = { NULL };
112
+ static char *keys[7] = { NULL };
113
+ static uint32_t hashes[7] = { 0 };
114
+ static ARL_BASE *bases[7] = { NULL };
115
116
if(unlikely(!arl_sockets)) {
117
do_sockets = config_get_boolean_ondemand("plugin:proc:/proc/net/sockstat", "ipv4 sockets", CONFIG_BOOLEAN_AUTO);
@@ -166,6 +164,7 @@ int do_proc_net_sockstat(int update_every, usec_t dt) {
164
keys[3] = "UDPLITE"; hashes[3] = hash_udplite; bases[3] = arl_udplite;
165
keys[4] = "RAW"; hashes[4] = hash_raw; bases[4] = arl_raw;
166
keys[5] = "FRAG"; hashes[5] = hash_frag; bases[5] = arl_frag;
167
+ keys[6] = NULL; // terminator
168
}
169
170
update_constants_count += update_every;
src/proc_net_sockstat6.c
new
+269
@@ -0,0 +1,269 @@
1
+#include "common.h"
2
+
3
+static struct proc_net_sockstat6 {
4
+ kernel_uint_t tcp6_inuse;
5
+ kernel_uint_t udp6_inuse;
6
+ kernel_uint_t udplite6_inuse;
7
+ kernel_uint_t raw6_inuse;
8
+ kernel_uint_t frag6_inuse;
9
+} sockstat6_root = { 0 };
10
+
11
+int do_proc_net_sockstat6(int update_every, usec_t dt) {
12
+ (void)dt;
13
+
14
+ static procfile *ff = NULL;
15
+
16
+ static uint32_t hash_raw = 0,
17
+ hash_frag = 0,
18
+ hash_tcp = 0,
19
+ hash_udp = 0,
20
+ hash_udplite = 0;
21
+
22
+ static ARL_BASE *arl_tcp = NULL;
23
+ static ARL_BASE *arl_udp = NULL;
24
+ static ARL_BASE *arl_udplite = NULL;
25
+ static ARL_BASE *arl_raw = NULL;
26
+ static ARL_BASE *arl_frag = NULL;
27
+
28
+ static int do_tcp_sockets = -1, do_udp_sockets = -1, do_udplite_sockets = -1, do_raw_sockets = -1, do_frag_sockets = -1;
29
+
30
+ static char *keys[6] = { NULL };
31
+ static uint32_t hashes[6] = { 0 };
32
+ static ARL_BASE *bases[6] = { NULL };
33
+
34
+ if(unlikely(!arl_tcp)) {
35
+ do_tcp_sockets = config_get_boolean_ondemand("plugin:proc:/proc/net/sockstat6", "ipv6 TCP sockets", CONFIG_BOOLEAN_AUTO);
36
+ do_udp_sockets = config_get_boolean_ondemand("plugin:proc:/proc/net/sockstat6", "ipv6 UDP sockets", CONFIG_BOOLEAN_AUTO);
37
+ do_udplite_sockets = config_get_boolean_ondemand("plugin:proc:/proc/net/sockstat6", "ipv6 UDPLITE sockets", CONFIG_BOOLEAN_AUTO);
38
+ do_raw_sockets = config_get_boolean_ondemand("plugin:proc:/proc/net/sockstat6", "ipv6 RAW sockets", CONFIG_BOOLEAN_AUTO);
39
+ do_frag_sockets = config_get_boolean_ondemand("plugin:proc:/proc/net/sockstat6", "ipv6 FRAG sockets", CONFIG_BOOLEAN_AUTO);
40
+
41
+ arl_tcp = arl_create("sockstat6/TCP6", arl_callback_str2kernel_uint_t, 60);
42
+ arl_expect(arl_tcp, "inuse", &sockstat6_root.tcp6_inuse);
43
+
44
+ arl_udp = arl_create("sockstat6/UDP6", arl_callback_str2kernel_uint_t, 60);
45
+ arl_expect(arl_udp, "inuse", &sockstat6_root.udp6_inuse);
46
+
47
+ arl_udplite = arl_create("sockstat6/UDPLITE6", arl_callback_str2kernel_uint_t, 60);
48
+ arl_expect(arl_udplite, "inuse", &sockstat6_root.udplite6_inuse);
49
+
50
+ arl_raw = arl_create("sockstat6/RAW6", arl_callback_str2kernel_uint_t, 60);
51
+ arl_expect(arl_raw, "inuse", &sockstat6_root.raw6_inuse);
52
+
53
+ arl_frag = arl_create("sockstat6/FRAG6", arl_callback_str2kernel_uint_t, 60);
54
+ arl_expect(arl_frag, "inuse", &sockstat6_root.frag6_inuse);
55
+
56
+ hash_tcp = simple_hash("TCP6");
57
+ hash_udp = simple_hash("UDP6");
58
+ hash_udplite = simple_hash("UDPLITE6");
59
+ hash_raw = simple_hash("RAW6");
60
+ hash_frag = simple_hash("FRAG6");
61
+
62
+ keys[0] = "TCP6"; hashes[0] = hash_tcp; bases[0] = arl_tcp;
63
+ keys[1] = "UDP6"; hashes[1] = hash_udp; bases[1] = arl_udp;
64
+ keys[2] = "UDPLITE6"; hashes[2] = hash_udplite; bases[2] = arl_udplite;
65
+ keys[3] = "RAW6"; hashes[3] = hash_raw; bases[3] = arl_raw;
66
+ keys[4] = "FRAG6"; hashes[4] = hash_frag; bases[4] = arl_frag;
67
+ keys[5] = NULL; // terminator
68
+ }
69
+
70
+ if(unlikely(!ff)) {
71
+ char filename[FILENAME_MAX + 1];
72
+ snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/net/sockstat6");
73
+ ff = procfile_open(config_get("plugin:proc:/proc/net/sockstat6", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
74
+ if(unlikely(!ff)) return 1;
75
+ }
76
+
77
+ ff = procfile_readall(ff);
78
+ if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
79
+
80
+ size_t lines = procfile_lines(ff), l;
81
+
82
+ for(l = 0; l < lines ;l++) {
83
+ size_t words = procfile_linewords(ff, l);
84
+ char *key = procfile_lineword(ff, l, 0);
85
+ uint32_t hash = simple_hash(key);
86
+
87
+ int k;
88
+ for(k = 0; keys[k] ; k++) {
89
+ if(unlikely(hash == hashes[k] && strcmp(key, keys[k]) == 0)) {
90
+ // fprintf(stderr, "KEY: '%s', l=%zu, w=1, words=%zu\n", key, l, words);
91
+ ARL_BASE *arl = bases[k];
92
+ arl_begin(arl);
93
+ size_t w = 1;
94
+
95
+ while(w + 1 < words) {
96
+ char *name = procfile_lineword(ff, l, w); w++;
97
+ char *value = procfile_lineword(ff, l, w); w++;
98
+ // fprintf(stderr, " > NAME '%s', VALUE '%s', l=%zu, w=%zu, words=%zu\n", name, value, l, w, words);
99
+ if(unlikely(arl_check(arl, name, value) != 0))
100
+ break;
101
+ }
102
+
103
+ break;
104
+ }
105
+ }
106
+ }
107
+
108
+ // ------------------------------------------------------------------------
109
+
110
+ if(do_tcp_sockets == CONFIG_BOOLEAN_YES || (do_tcp_sockets == CONFIG_BOOLEAN_AUTO && (sockstat6_root.tcp6_inuse))) {
111
+ do_tcp_sockets = CONFIG_BOOLEAN_YES;
112
+
113
+ static RRDSET *st = NULL;
114
+ static RRDDIM *rd_inuse = NULL;
115
+
116
+ if(unlikely(!st)) {
117
+ st = rrdset_create_localhost(
118
+ "ipv6"
119
+ , "sockstat6_tcp_sockets"
120
+ , NULL
121
+ , "tcp6"
122
+ , NULL
123
+ , "IPv6 TCP Sockets"
124
+ , "tcp6"
125
+ , "proc"
126
+ , "net/sockstat6"
127
+ , 3599
128
+ , update_every
129
+ , RRDSET_TYPE_LINE
130
+ );
131
+
132
+ rd_inuse = rrddim_add(st, "inuse", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
133
+ }
134
+ else rrdset_next(st);
135
+
136
+ rrddim_set_by_pointer(st, rd_inuse, (collected_number)sockstat6_root.tcp6_inuse);
137
+ rrdset_done(st);
138
+ }
139
+
140
+ // ------------------------------------------------------------------------
141
+
142
+ if(do_udp_sockets == CONFIG_BOOLEAN_YES || (do_udp_sockets == CONFIG_BOOLEAN_AUTO && sockstat6_root.udp6_inuse)) {
143
+ do_udp_sockets = CONFIG_BOOLEAN_YES;
144
+
145
+ static RRDSET *st = NULL;
146
+ static RRDDIM *rd_inuse = NULL;
147
+
148
+ if(unlikely(!st)) {
149
+ st = rrdset_create_localhost(
150
+ "ipv6"
151
+ , "sockstat6_udp_sockets"
152
+ , NULL
153
+ , "udp6"
154
+ , NULL
155
+ , "IPv6 UDP Sockets"
156
+ , "sockets"
157
+ , "proc"
158
+ , "net/sockstat6"
159
+ , 3600
160
+ , update_every
161
+ , RRDSET_TYPE_LINE
162
+ );
163
+
164
+ rd_inuse = rrddim_add(st, "inuse", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
165
+ }
166
+ else rrdset_next(st);
167
+
168
+ rrddim_set_by_pointer(st, rd_inuse, (collected_number)sockstat6_root.udp6_inuse);
169
+ rrdset_done(st);
170
+ }
171
+
172
+ // ------------------------------------------------------------------------
173
+
174
+ if(do_udplite_sockets == CONFIG_BOOLEAN_YES || (do_udplite_sockets == CONFIG_BOOLEAN_AUTO && sockstat6_root.udplite6_inuse)) {
175
+ do_udplite_sockets = CONFIG_BOOLEAN_YES;
176
+
177
+ static RRDSET *st = NULL;
178
+ static RRDDIM *rd_inuse = NULL;
179
+
180
+ if(unlikely(!st)) {
181
+ st = rrdset_create_localhost(
182
+ "ipv6"
183
+ , "sockstat6_udplite_sockets"
184
+ , NULL
185
+ , "udplite6"
186
+ , NULL
187
+ , "IPv6 UDPLITE Sockets"
188
+ , "sockets"
189
+ , "proc"
190
+ , "net/sockstat6"
191
+ , 3601
192
+ , update_every
193
+ , RRDSET_TYPE_LINE
194
+ );
195
+
196
+ rd_inuse = rrddim_add(st, "inuse", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
197
+ }
198
+ else rrdset_next(st);
199
+
200
+ rrddim_set_by_pointer(st, rd_inuse, (collected_number)sockstat6_root.udplite6_inuse);
201
+ rrdset_done(st);
202
+ }
203
+
204
+ // ------------------------------------------------------------------------
205
+
206
+ if(do_raw_sockets == CONFIG_BOOLEAN_YES || (do_raw_sockets == CONFIG_BOOLEAN_AUTO && sockstat6_root.raw6_inuse)) {
207
+ do_raw_sockets = CONFIG_BOOLEAN_YES;
208
+
209
+ static RRDSET *st = NULL;
210
+ static RRDDIM *rd_inuse = NULL;
211
+
212
+ if(unlikely(!st)) {
213
+ st = rrdset_create_localhost(
214
+ "ipv6"
215
+ , "sockstat6_raw_sockets"
216
+ , NULL
217
+ , "raw6"
218
+ , NULL
219
+ , "IPv6 RAW Sockets"
220
+ , "sockets"
221
+ , "proc"
222
+ , "net/sockstat6"
223
+ , 3700
224
+ , update_every
225
+ , RRDSET_TYPE_LINE
226
+ );
227
+
228
+ rd_inuse = rrddim_add(st, "inuse", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
229
+ }
230
+ else rrdset_next(st);
231
+
232
+ rrddim_set_by_pointer(st, rd_inuse, (collected_number)sockstat6_root.raw6_inuse);
233
+ rrdset_done(st);
234
+ }
235
+
236
+ // ------------------------------------------------------------------------
237
+
238
+ if(do_frag_sockets == CONFIG_BOOLEAN_YES || (do_frag_sockets == CONFIG_BOOLEAN_AUTO && sockstat6_root.frag6_inuse)) {
239
+ do_frag_sockets = CONFIG_BOOLEAN_YES;
240
+
241
+ static RRDSET *st = NULL;
242
+ static RRDDIM *rd_inuse = NULL;
243
+
244
+ if(unlikely(!st)) {
245
+ st = rrdset_create_localhost(
246
+ "ipv6"
247
+ , "sockstat6_frag_sockets"
248
+ , NULL
249
+ , "fragments6"
250
+ , NULL
251
+ , "IPv6 FRAG Sockets"
252
+ , "fragments"
253
+ , "proc"
254
+ , "net/sockstat6"
255
+ , 3010
256
+ , update_every
257
+ , RRDSET_TYPE_LINE
258
+ );
259
+
260
+ rd_inuse = rrddim_add(st, "inuse", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
261
+ }
262
+ else rrdset_next(st);
263
+
264
+ rrddim_set_by_pointer(st, rd_inuse, (collected_number)sockstat6_root.frag6_inuse);
265
+ rrdset_done(st);
266
+ }
267
+
268
+ return 0;
269
+}