@cryptotaxi247 / netdata-1 / commits / a15f2eed7

refactored /proc/net/dev plugin for speed and also added option to disable veth interfaces

Costa Tsaousis (ktsaou) committed Jan 12, 2017 at 23:15 UTC a15f2eed7e97a7f31b4a3b2508a6a3dae45b365c
1 file changed +295 -157
src/proc_net_dev.c
+295 -157
@@ -1,233 +1,371 @@
1 #include "common.h"
2
3 +struct netdev {
4 + char *name;
5 + uint32_t hash;
6 + size_t len;
7 +
8 + // flags
9 + int configured;
10 + int enabled;
11 +
12 + int do_bandwidth;
13 + int do_packets;
14 + int do_errors;
15 + int do_drops;
16 + int do_fifo;
17 + int do_compressed;
18 + int do_events;
19 +
20 + // data collected
21 + unsigned long long rbytes;
22 + unsigned long long rpackets;
23 + unsigned long long rerrors;
24 + unsigned long long rdrops;
25 + unsigned long long rfifo;
26 + unsigned long long rframe;
27 + unsigned long long rcompressed;
28 + unsigned long long rmulticast;
29 +
30 + unsigned long long tbytes;
31 + unsigned long long tpackets;
32 + unsigned long long terrors;
33 + unsigned long long tdrops;
34 + unsigned long long tfifo;
35 + unsigned long long tcollisions;
36 + unsigned long long tcarrier;
37 + unsigned long long tcompressed;
38 +
39 + // charts
40 + RRDSET *st_bandwidth;
41 + RRDSET *st_packets;
42 + RRDSET *st_errors;
43 + RRDSET *st_drops;
44 + RRDSET *st_fifo;
45 + RRDSET *st_compressed;
46 + RRDSET *st_events;
47 +
48 + // dimensions
49 + RRDDIM *rd_rbytes;
50 + RRDDIM *rd_rpackets;
51 + RRDDIM *rd_rerrors;
52 + RRDDIM *rd_rdrops;
53 + RRDDIM *rd_rfifo;
54 + RRDDIM *rd_rframe;
55 + RRDDIM *rd_rcompressed;
56 + RRDDIM *rd_rmulticast;
57 +
58 + RRDDIM *rd_tbytes;
59 + RRDDIM *rd_tpackets;
60 + RRDDIM *rd_terrors;
61 + RRDDIM *rd_tdrops;
62 + RRDDIM *rd_tfifo;
63 + RRDDIM *rd_tcollisions;
64 + RRDDIM *rd_tcarrier;
65 + RRDDIM *rd_tcompressed;
66 +
67 + struct netdev *next;
68 +};
69 +
70 +static struct netdev *netdev_root = NULL;
71 +
72 +static struct netdev *get_netdev(const char *name) {
73 + static struct netdev *last = NULL;
74 + struct netdev *d;
75 +
76 + uint32_t hash = simple_hash(name);
77 +
78 + // search it, from the last position to the end
79 + for(d = last ; d ; d = d->next) {
80 + if(unlikely(hash == d->hash && !strcmp(name, d->name))) {
81 + last = d->next;
82 + return d;
83 + }
84 + }
85 +
86 + // search it from the beginning to the last position we used
87 + for(d = netdev_root ; d != last ; d = d->next) {
88 + if(unlikely(hash == d->hash && !strcmp(name, d->name))) {
89 + last = d->next;
90 + return d;
91 + }
92 + }
93 +
94 + // create a new one
95 + d = callocz(1, sizeof(struct netdev));
96 + d->name = strdupz(name);
97 + d->hash = simple_hash(d->name);
98 + d->len = strlen(d->name);
99 +
100 + // link it to the end
101 + if(netdev_root) {
102 + struct netdev *e;
103 + for(e = netdev_root; e->next ; e = e->next) ;
104 + e->next = d;
105 + }
106 + else
107 + netdev_root = d;
108 +
109 + return d;
110 +}
111 +
112 int do_proc_net_dev(int update_every, usec_t dt) {
113 + (void)dt;
114 +
115 static procfile *ff = NULL;
5 - static int enable_new_interfaces = -1, enable_ifb_interfaces = -1;
116 + static int enable_new_interfaces = -1, enable_ifb_interfaces = -1, enable_veth_interfaces = -1;
117 static int do_bandwidth = -1, do_packets = -1, do_errors = -1, do_drops = -1, do_fifo = -1, do_compressed = -1, do_events = -1;
118
8 - if(dt) {};
119 + if(unlikely(enable_new_interfaces == -1)) {
120 + enable_new_interfaces = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "enable new interfaces detected at runtime", CONFIG_ONDEMAND_ONDEMAND);
121 + enable_ifb_interfaces = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "enable ifb interfaces", CONFIG_ONDEMAND_NO);
122 + enable_veth_interfaces = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "enable veth interfaces", enable_new_interfaces);
123 +
124 + do_bandwidth = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "bandwidth for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
125 + do_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "packets for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
126 + do_errors = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "errors for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
127 + do_drops = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "drops for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
128 + do_fifo = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "fifo for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
129 + do_compressed = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "compressed packets for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
130 + do_events = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "frames, collisions, carrier counters for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
131 + }
132
10 - if(!ff) {
133 + if(unlikely(!ff)) {
134 char filename[FILENAME_MAX + 1];
135 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/dev");
136 ff = procfile_open(config_get("plugin:proc:/proc/net/dev", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
137 + if(unlikely(!ff)) return 1;
138 }
15 - if(!ff) return 1;
139
140 ff = procfile_readall(ff);
141 if(!ff) return 0; // we return 0, so that we will retry to open it next time
142
20 - if(enable_new_interfaces == -1) enable_new_interfaces = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "enable new interfaces detected at runtime", CONFIG_ONDEMAND_ONDEMAND);
21 - if(enable_ifb_interfaces == -1) enable_ifb_interfaces = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "enable ifb interfaces", CONFIG_ONDEMAND_NO);
22 -
23 - if(do_bandwidth == -1) do_bandwidth = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "bandwidth for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
24 - if(do_packets == -1) do_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "packets for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
25 - if(do_errors == -1) do_errors = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "errors for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
26 - if(do_drops == -1) do_drops = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "drops for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
27 - if(do_fifo == -1) do_fifo = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "fifo for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
28 - if(do_compressed == -1) do_compressed = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "compressed packets for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
29 - if(do_events == -1) do_events = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "frames, collisions, carrier counters for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
30 -
143 uint32_t lines = procfile_lines(ff), l;
144
33 - char *iface;
34 - unsigned long long rbytes, rpackets, rerrors, rdrops, rfifo, rframe, rcompressed, rmulticast;
35 - unsigned long long tbytes, tpackets, terrors, tdrops, tfifo, tcollisions, tcarrier, tcompressed;
36 -
145 for(l = 2; l < lines ;l++) {
146 uint32_t words = procfile_linewords(ff, l);
147 if(words < 17) continue;
148
41 - iface = procfile_lineword(ff, l, 0);
42 -
43 - rbytes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
44 - rpackets = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
45 - rerrors = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
46 - rdrops = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
47 - rfifo = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
48 - rframe = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
49 - rcompressed = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
50 - rmulticast = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
51 -
52 - tbytes = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
53 - tpackets = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
54 - terrors = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
55 - tdrops = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
56 - tfifo = strtoull(procfile_lineword(ff, l, 13), NULL, 10);
57 - tcollisions = strtoull(procfile_lineword(ff, l, 14), NULL, 10);
58 - tcarrier = strtoull(procfile_lineword(ff, l, 15), NULL, 10);
59 - tcompressed = strtoull(procfile_lineword(ff, l, 16), NULL, 10);
60 -
61 - int ddo_bandwidth = do_bandwidth, ddo_packets = do_packets, ddo_errors = do_errors, ddo_drops = do_drops, ddo_fifo = do_fifo, ddo_compressed = do_compressed, ddo_events = do_events;
62 -
63 - int default_enable = enable_new_interfaces;
64 -
65 - // prevent unused interfaces from creating charts
66 - if(strcmp(iface, "lo") == 0)
67 - default_enable = 0;
68 - else {
69 - int len = strlen(iface);
70 - if(len >= 4 && strcmp(&iface[len-4], "-ifb") == 0)
71 - default_enable = enable_ifb_interfaces;
72 - }
149 + struct netdev *d = get_netdev(procfile_lineword(ff, l, 0));
150 +
151 + if(unlikely(!d->configured)) {
152 + d->configured = 1;
153 +
154 + d->enabled = enable_new_interfaces;
155 +
156 + if(d->enabled) {
157 + if(unlikely(!strcmp(d->name, "lo")))
158 + d->enabled = CONFIG_ONDEMAND_NO;
159 + else if(unlikely(!strncmp(d->name, "veth", 4)))
160 + d->enabled = enable_veth_interfaces;
161 + else if(unlikely(d->len >= 4 && strcmp(&d->name[d->len - 4], "-ifb") == 0))
162 + d->enabled = enable_ifb_interfaces;
163 + }
164 +
165 + if(d->enabled == CONFIG_ONDEMAND_NO)
166 + continue;
167
74 - // check if the user wants it
75 - {
168 char var_name[512 + 1];
77 - snprintfz(var_name, 512, "plugin:proc:/proc/net/dev:%s", iface);
78 - default_enable = config_get_boolean_ondemand(var_name, "enabled", default_enable);
79 - if(default_enable == CONFIG_ONDEMAND_NO) continue;
80 - if(default_enable == CONFIG_ONDEMAND_ONDEMAND && !rbytes && !tbytes) continue;
81 -
82 - ddo_bandwidth = config_get_boolean_ondemand(var_name, "bandwidth", ddo_bandwidth);
83 - ddo_packets = config_get_boolean_ondemand(var_name, "packets", ddo_packets);
84 - ddo_errors = config_get_boolean_ondemand(var_name, "errors", ddo_errors);
85 - ddo_drops = config_get_boolean_ondemand(var_name, "drops", ddo_drops);
86 - ddo_fifo = config_get_boolean_ondemand(var_name, "fifo", ddo_fifo);
87 - ddo_compressed = config_get_boolean_ondemand(var_name, "compressed", ddo_compressed);
88 - ddo_events = config_get_boolean_ondemand(var_name, "events", ddo_events);
89 -
90 - if(ddo_bandwidth == CONFIG_ONDEMAND_ONDEMAND && rbytes == 0 && tbytes == 0) ddo_bandwidth = 0;
91 - if(ddo_errors == CONFIG_ONDEMAND_ONDEMAND && rerrors == 0 && terrors == 0) ddo_errors = 0;
92 - if(ddo_drops == CONFIG_ONDEMAND_ONDEMAND && rdrops == 0 && tdrops == 0) ddo_drops = 0;
93 - if(ddo_fifo == CONFIG_ONDEMAND_ONDEMAND && rfifo == 0 && tfifo == 0) ddo_fifo = 0;
94 - if(ddo_compressed == CONFIG_ONDEMAND_ONDEMAND && rcompressed == 0 && tcompressed == 0) ddo_compressed = 0;
95 - if(ddo_events == CONFIG_ONDEMAND_ONDEMAND && rframe == 0 && tcollisions == 0 && tcarrier == 0) ddo_events = 0;
96 -
97 - // for absolute values, we need to switch the setting to 'yes'
98 - // to allow it refresh from now on
99 - // if(ddo_fifo == CONFIG_ONDEMAND_ONDEMAND) config_set(var_name, "fifo", "yes");
169 + snprintfz(var_name, 512, "plugin:proc:/proc/net/dev:%s", d->name);
170 + d->enabled = config_get_boolean_ondemand(var_name, "enabled", d->enabled);
171 + if(d->enabled == CONFIG_ONDEMAND_NO) continue;
172 +
173 + d->do_bandwidth = config_get_boolean_ondemand(var_name, "bandwidth", do_bandwidth);
174 + d->do_packets = config_get_boolean_ondemand(var_name, "packets", do_packets);
175 + d->do_errors = config_get_boolean_ondemand(var_name, "errors", do_errors);
176 + d->do_drops = config_get_boolean_ondemand(var_name, "drops", do_drops);
177 + d->do_fifo = config_get_boolean_ondemand(var_name, "fifo", do_fifo);
178 + d->do_compressed = config_get_boolean_ondemand(var_name, "compressed", do_compressed);
179 + d->do_events = config_get_boolean_ondemand(var_name, "events", do_events);
180 }
181
102 - RRDSET *st;
182 + if(unlikely(!d->enabled))
183 + continue;
184 +
185 + d->rbytes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
186 + d->rpackets = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
187 + d->rerrors = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
188 + d->rdrops = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
189 + d->rfifo = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
190 + d->rframe = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
191 + d->rcompressed = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
192 + d->rmulticast = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
193 +
194 + d->tbytes = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
195 + d->tpackets = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
196 + d->terrors = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
197 + d->tdrops = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
198 + d->tfifo = strtoull(procfile_lineword(ff, l, 13), NULL, 10);
199 + d->tcollisions = strtoull(procfile_lineword(ff, l, 14), NULL, 10);
200 + d->tcarrier = strtoull(procfile_lineword(ff, l, 15), NULL, 10);
201 + d->tcompressed = strtoull(procfile_lineword(ff, l, 16), NULL, 10);
202
203 // --------------------------------------------------------------------
204
106 - if(ddo_bandwidth) {
107 - st = rrdset_find_bytype("net", iface);
108 - if(!st) {
109 - st = rrdset_create("net", iface, NULL, iface, "net.net", "Bandwidth", "kilobits/s", 7000, update_every, RRDSET_TYPE_AREA);
205 + if(unlikely((d->do_bandwidth == CONFIG_ONDEMAND_ONDEMAND && (d->rbytes || d->tbytes))))
206 + d->do_bandwidth = CONFIG_ONDEMAND_YES;
207 +
208 + if(d->do_bandwidth == CONFIG_ONDEMAND_YES) {
209 + if(unlikely(!d->st_bandwidth)) {
210 + d->st_bandwidth = rrdset_find_bytype("net", d->name);
211
111 - rrddim_add(st, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
112 - rrddim_add(st, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
212 + if(!d->st_bandwidth) {
213 + d->st_bandwidth = rrdset_create("net", d->name, NULL, d->name, "net.net", "Bandwidth", "kilobits/s", 7000, update_every, RRDSET_TYPE_AREA);
214 + d->rd_rbytes = rrddim_add(d->st_bandwidth, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
215 + d->rd_tbytes = rrddim_add(d->st_bandwidth, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
216 + }
217 }
114 - else rrdset_next(st);
218 + else rrdset_next(d->st_bandwidth);
219
116 - rrddim_set(st, "received", rbytes);
117 - rrddim_set(st, "sent", tbytes);
118 - rrdset_done(st);
220 + rrddim_set_by_pointer(d->st_bandwidth, d->rd_rbytes, d->rbytes);
221 + rrddim_set_by_pointer(d->st_bandwidth, d->rd_tbytes, d->tbytes);
222 + rrdset_done(d->st_bandwidth);
223 }
224
225 // --------------------------------------------------------------------
226
123 - if(ddo_packets) {
124 - st = rrdset_find_bytype("net_packets", iface);
125 - if(!st) {
126 - st = rrdset_create("net_packets", iface, NULL, iface, "net.packets", "Packets", "packets/s", 7001, update_every, RRDSET_TYPE_LINE);
127 - st->isdetail = 1;
227 + if(unlikely((d->do_packets == CONFIG_ONDEMAND_ONDEMAND && (d->rpackets || d->tpackets || d->rmulticast))))
228 + d->do_packets = CONFIG_ONDEMAND_YES;
229 +
230 + if(d->do_packets == CONFIG_ONDEMAND_YES) {
231 + if(unlikely(!d->st_packets)) {
232 + d->st_packets = rrdset_find_bytype("net_packets", d->name);
233 +
234 + if(!d->st_packets) {
235 + d->st_packets = rrdset_create("net_packets", d->name, NULL, d->name, "net.packets", "Packets", "packets/s", 7001, update_every, RRDSET_TYPE_LINE);
236 + d->st_packets->isdetail = 1;
237
129 - rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
130 - rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
131 - rrddim_add(st, "multicast", NULL, 1, 1, RRDDIM_INCREMENTAL);
238 + d->rd_rpackets = rrddim_add(d->st_packets, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
239 + d->rd_tpackets = rrddim_add(d->st_packets, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
240 + d->rd_rmulticast = rrddim_add(d->st_packets, "multicast", NULL, 1, 1, RRDDIM_INCREMENTAL);
241 + }
242 }
133 - else rrdset_next(st);
243 + else rrdset_next(d->st_packets);
244
135 - rrddim_set(st, "received", rpackets);
136 - rrddim_set(st, "sent", tpackets);
137 - rrddim_set(st, "multicast", rmulticast);
138 - rrdset_done(st);
245 + rrddim_set_by_pointer(d->st_packets, d->rd_rpackets, d->rpackets);
246 + rrddim_set_by_pointer(d->st_packets, d->rd_tpackets, d->tpackets);
247 + rrddim_set_by_pointer(d->st_packets, d->rd_rmulticast, d->rmulticast);
248 + rrdset_done(d->st_packets);
249 }
250
251 // --------------------------------------------------------------------
252
143 - if(ddo_errors) {
144 - st = rrdset_find_bytype("net_errors", iface);
145 - if(!st) {
146 - st = rrdset_create("net_errors", iface, NULL, iface, "net.errors", "Interface Errors", "errors/s", 7002, update_every, RRDSET_TYPE_LINE);
147 - st->isdetail = 1;
253 + if(unlikely((d->do_errors == CONFIG_ONDEMAND_ONDEMAND && (d->rerrors || d->terrors))))
254 + d->do_errors = CONFIG_ONDEMAND_YES;
255
149 - rrddim_add(st, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
150 - rrddim_add(st, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
256 + if(d->do_errors == CONFIG_ONDEMAND_YES) {
257 + if(unlikely(!d->st_errors)) {
258 + d->st_errors = rrdset_find_bytype("net_errors", d->name);
259 +
260 + if(!d->st_errors) {
261 + d->st_errors = rrdset_create("net_errors", d->name, NULL, d->name, "net.errors", "Interface Errors", "errors/s", 7002, update_every, RRDSET_TYPE_LINE);
262 + d->st_errors->isdetail = 1;
263 +
264 + d->rd_rerrors = rrddim_add(d->st_errors, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
265 + d->rd_terrors = rrddim_add(d->st_errors, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
266 + }
267 }
152 - else rrdset_next(st);
268 + else rrdset_next(d->st_errors);
269
154 - rrddim_set(st, "inbound", rerrors);
155 - rrddim_set(st, "outbound", terrors);
156 - rrdset_done(st);
270 + rrddim_set_by_pointer(d->st_errors, d->rd_rerrors, d->rerrors);
271 + rrddim_set_by_pointer(d->st_errors, d->rd_terrors, d->terrors);
272 + rrdset_done(d->st_errors);
273 }
274
275 // --------------------------------------------------------------------
276
161 - if(ddo_drops) {
162 - st = rrdset_find_bytype("net_drops", iface);
163 - if(!st) {
164 - st = rrdset_create("net_drops", iface, NULL, iface, "net.drops", "Interface Drops", "drops/s", 7003, update_every, RRDSET_TYPE_LINE);
165 - st->isdetail = 1;
277 + if(unlikely((d->do_drops == CONFIG_ONDEMAND_ONDEMAND && (d->rdrops || d->tdrops))))
278 + d->do_drops = CONFIG_ONDEMAND_YES;
279 +
280 + if(d->do_drops == CONFIG_ONDEMAND_YES) {
281 + if(unlikely(!d->st_drops)) {
282 + d->st_drops = rrdset_find_bytype("net_drops", d->name);
283 +
284 + if(!d->st_drops) {
285 + d->st_drops = rrdset_create("net_drops", d->name, NULL, d->name, "net.drops", "Interface Drops", "drops/s", 7003, update_every, RRDSET_TYPE_LINE);
286 + d->st_drops->isdetail = 1;
287
167 - rrddim_add(st, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
168 - rrddim_add(st, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
288 + d->rd_rdrops = rrddim_add(d->st_drops, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
289 + d->rd_tdrops = rrddim_add(d->st_drops, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
290 + }
291 }
170 - else rrdset_next(st);
292 + else rrdset_next(d->st_drops);
293
172 - rrddim_set(st, "inbound", rdrops);
173 - rrddim_set(st, "outbound", tdrops);
174 - rrdset_done(st);
294 + rrddim_set_by_pointer(d->st_drops, d->rd_rdrops, d->rdrops);
295 + rrddim_set_by_pointer(d->st_drops, d->rd_tdrops, d->tdrops);
296 + rrdset_done(d->st_drops);
297 }
298
299 // --------------------------------------------------------------------
300
179 - if(ddo_fifo) {
180 - st = rrdset_find_bytype("net_fifo", iface);
181 - if(!st) {
182 - st = rrdset_create("net_fifo", iface, NULL, iface, "net.fifo", "Interface FIFO Buffer Errors", "errors", 7004, update_every, RRDSET_TYPE_LINE);
183 - st->isdetail = 1;
301 + if(unlikely((d->do_fifo == CONFIG_ONDEMAND_ONDEMAND && (d->rfifo || d->tfifo))))
302 + d->do_fifo = CONFIG_ONDEMAND_YES;
303
185 - rrddim_add(st, "receive", NULL, 1, 1, RRDDIM_INCREMENTAL);
186 - rrddim_add(st, "transmit", NULL, -1, 1, RRDDIM_INCREMENTAL);
304 + if(d->do_fifo == CONFIG_ONDEMAND_YES) {
305 + if(unlikely(!d->st_fifo)) {
306 + d->st_fifo = rrdset_find_bytype("net_fifo", d->name);
307 +
308 + if(!d->st_fifo) {
309 + d->st_fifo = rrdset_create("net_fifo", d->name, NULL, d->name, "net.fifo", "Interface FIFO Buffer Errors", "errors", 7004, update_every, RRDSET_TYPE_LINE);
310 + d->st_fifo->isdetail = 1;
311 +
312 + d->rd_rfifo = rrddim_add(d->st_fifo, "receive", NULL, 1, 1, RRDDIM_INCREMENTAL);
313 + d->rd_tfifo = rrddim_add(d->st_fifo, "transmit", NULL, -1, 1, RRDDIM_INCREMENTAL);
314 + }
315 }
188 - else rrdset_next(st);
316 + else rrdset_next(d->st_fifo);
317
190 - rrddim_set(st, "receive", rfifo);
191 - rrddim_set(st, "transmit", tfifo);
192 - rrdset_done(st);
318 + rrddim_set_by_pointer(d->st_fifo, d->rd_rfifo, d->rfifo);
319 + rrddim_set_by_pointer(d->st_fifo, d->rd_tfifo, d->tfifo);
320 + rrdset_done(d->st_fifo);
321 }
322
323 // --------------------------------------------------------------------
324
197 - if(ddo_compressed) {
198 - st = rrdset_find_bytype("net_compressed", iface);
199 - if(!st) {
200 - st = rrdset_create("net_compressed", iface, NULL, iface, "net.compressed", "Compressed Packets", "packets/s", 7005, update_every, RRDSET_TYPE_LINE);
201 - st->isdetail = 1;
325 + if(unlikely((d->do_compressed == CONFIG_ONDEMAND_ONDEMAND && (d->rcompressed || d->tcompressed))))
326 + d->do_compressed = CONFIG_ONDEMAND_YES;
327
203 - rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
204 - rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
328 + if(d->do_compressed == CONFIG_ONDEMAND_YES) {
329 + if(unlikely(!d->st_compressed)) {
330 + d->st_compressed = rrdset_find_bytype("net_compressed", d->name);
331 + if(!d->st_compressed) {
332 + d->st_compressed = rrdset_create("net_compressed", d->name, NULL, d->name, "net.compressed", "Compressed Packets", "packets/s", 7005, update_every, RRDSET_TYPE_LINE);
333 + d->st_compressed->isdetail = 1;
334 +
335 + d->rd_rcompressed = rrddim_add(d->st_compressed, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
336 + d->rd_tcompressed = rrddim_add(d->st_compressed, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
337 + }
338 }
206 - else rrdset_next(st);
339 + else rrdset_next(d->st_compressed);
340
208 - rrddim_set(st, "received", rcompressed);
209 - rrddim_set(st, "sent", tcompressed);
210 - rrdset_done(st);
341 + rrddim_set_by_pointer(d->st_compressed, d->rd_rcompressed, d->rcompressed);
342 + rrddim_set_by_pointer(d->st_compressed, d->rd_tcompressed, d->tcompressed);
343 + rrdset_done(d->st_compressed);
344 }
345
346 // --------------------------------------------------------------------
347
215 - if(ddo_events) {
216 - st = rrdset_find_bytype("net_events", iface);
217 - if(!st) {
218 - st = rrdset_create("net_events", iface, NULL, iface, "net.events", "Network Interface Events", "events/s", 7006, update_every, RRDSET_TYPE_LINE);
219 - st->isdetail = 1;
348 + if(unlikely((d->do_events == CONFIG_ONDEMAND_ONDEMAND && (d->rframe || d->tcollisions || d->tcarrier))))
349 + d->do_events = CONFIG_ONDEMAND_YES;
350 +
351 + if(d->do_events == CONFIG_ONDEMAND_YES) {
352 + if(unlikely(!d->st_events)) {
353 + d->st_events = rrdset_find_bytype("net_events", d->name);
354 + if(!d->st_events) {
355 + d->st_events = rrdset_create("net_events", d->name, NULL, d->name, "net.events", "Network Interface Events", "events/s", 7006, update_every, RRDSET_TYPE_LINE);
356 + d->st_events->isdetail = 1;
357
221 - rrddim_add(st, "frames", NULL, 1, 1, RRDDIM_INCREMENTAL);
222 - rrddim_add(st, "collisions", NULL, -1, 1, RRDDIM_INCREMENTAL);
223 - rrddim_add(st, "carrier", NULL, -1, 1, RRDDIM_INCREMENTAL);
358 + d->rd_rframe = rrddim_add(d->st_events, "frames", NULL, 1, 1, RRDDIM_INCREMENTAL);
359 + d->rd_tcollisions = rrddim_add(d->st_events, "collisions", NULL, -1, 1, RRDDIM_INCREMENTAL);
360 + d->rd_tcarrier = rrddim_add(d->st_events, "carrier", NULL, -1, 1, RRDDIM_INCREMENTAL);
361 + }
362 }
225 - else rrdset_next(st);
363 + else rrdset_next(d->st_events);
364
227 - rrddim_set(st, "frames", rframe);
228 - rrddim_set(st, "collisions", tcollisions);
229 - rrddim_set(st, "carrier", tcarrier);
230 - rrdset_done(st);
365 + rrddim_set_by_pointer(d->st_events, d->rd_rframe, d->rframe);
366 + rrddim_set_by_pointer(d->st_events, d->rd_tcollisions, d->tcollisions);
367 + rrddim_set_by_pointer(d->st_events, d->rd_tcarrier, d->tcarrier);
368 + rrdset_done(d->st_events);
369 }
370 }
371