int do_events;
// data collected
- unsigned long long rbytes;
- unsigned long long rpackets;
- unsigned long long rerrors;
- unsigned long long rdrops;
- unsigned long long rfifo;
- unsigned long long rframe;
- unsigned long long rcompressed;
- unsigned long long rmulticast;
-
- unsigned long long tbytes;
- unsigned long long tpackets;
- unsigned long long terrors;
- unsigned long long tdrops;
- unsigned long long tfifo;
- unsigned long long tcollisions;
- unsigned long long tcarrier;
- unsigned long long tcompressed;
+ kernel_uint_t rbytes;
+ kernel_uint_t rpackets;
+ kernel_uint_t rerrors;
+ kernel_uint_t rdrops;
+ kernel_uint_t rfifo;
+ kernel_uint_t rframe;
+ kernel_uint_t rcompressed;
+ kernel_uint_t rmulticast;
+
+ kernel_uint_t tbytes;
+ kernel_uint_t tpackets;
+ kernel_uint_t terrors;
+ kernel_uint_t tdrops;
+ kernel_uint_t tfifo;
+ kernel_uint_t tcollisions;
+ kernel_uint_t tcarrier;
+ kernel_uint_t tcompressed;
// charts
RRDSET *st_bandwidth;
int do_proc_net_dev(int update_every, usec_t dt) {
(void)dt;
-
+ static SIMPLE_PATTERN *disabled_list = NULL;
static procfile *ff = NULL;
- static int enable_new_interfaces = -1, enable_ifb_interfaces = -1, enable_veth_interfaces = -1;
+ static int enable_new_interfaces = -1;
static int do_bandwidth = -1, do_packets = -1, do_errors = -1, do_drops = -1, do_fifo = -1, do_compressed = -1, do_events = -1;
if(unlikely(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);
- enable_ifb_interfaces = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "enable ifb interfaces", CONFIG_ONDEMAND_NO);
- enable_veth_interfaces = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "enable veth interfaces", enable_new_interfaces);
do_bandwidth = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "bandwidth for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
do_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "packets for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
do_fifo = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "fifo for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
do_compressed = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "compressed packets for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
do_events = config_get_boolean_ondemand("plugin:proc:/proc/net/dev", "frames, collisions, carrier counters for all interfaces", CONFIG_ONDEMAND_ONDEMAND);
+
+ disabled_list = simple_pattern_create(
+ config_get("plugin:proc:/proc/net/dev", "disable by default interfaces matching", "lo fireqos* *-ifb")
+ , SIMPLE_PATTERN_EXACT);
}
if(unlikely(!ff)) {
char filename[FILENAME_MAX + 1];
- snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/dev");
+ snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/net/dev");
ff = procfile_open(config_get("plugin:proc:/proc/net/dev", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
if(unlikely(!ff)) return 1;
}
ff = procfile_readall(ff);
- if(!ff) return 0; // we return 0, so that we will retry to open it next time
-
- uint32_t lines = procfile_lines(ff), l;
+ if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
+ size_t lines = procfile_lines(ff), l;
for(l = 2; l < lines ;l++) {
- uint32_t words = procfile_linewords(ff, l);
- if(words < 17) continue;
+ // require 17 words on each line
+ if(unlikely(procfile_linewords(ff, l) < 17)) continue;
struct netdev *d = get_netdev(procfile_lineword(ff, l, 0));
if(unlikely(!d->configured)) {
+ // this is the first time we see this interface
+
+ // remember we configured it
d->configured = 1;
d->enabled = enable_new_interfaces;
- if(d->enabled) {
- if(unlikely(!strcmp(d->name, "lo")))
- d->enabled = CONFIG_ONDEMAND_NO;
- else if(unlikely(!strncmp(d->name, "veth", 4)))
- d->enabled = enable_veth_interfaces;
- else if(unlikely(d->len >= 4 && strcmp(&d->name[d->len - 4], "-ifb") == 0))
- d->enabled = enable_ifb_interfaces;
- }
+ if(d->enabled)
+ d->enabled = !simple_pattern_matches(disabled_list, d->name);
char var_name[512 + 1];
snprintfz(var_name, 512, "plugin:proc:/proc/net/dev:%s", d->name);
if(d->enabled == CONFIG_ONDEMAND_NO)
continue;
- d->do_bandwidth = config_get_boolean_ondemand(var_name, "bandwidth", do_bandwidth);
- d->do_packets = config_get_boolean_ondemand(var_name, "packets", do_packets);
- d->do_errors = config_get_boolean_ondemand(var_name, "errors", do_errors);
- d->do_drops = config_get_boolean_ondemand(var_name, "drops", do_drops);
- d->do_fifo = config_get_boolean_ondemand(var_name, "fifo", do_fifo);
+ d->do_bandwidth = config_get_boolean_ondemand(var_name, "bandwidth", do_bandwidth);
+ d->do_packets = config_get_boolean_ondemand(var_name, "packets", do_packets);
+ d->do_errors = config_get_boolean_ondemand(var_name, "errors", do_errors);
+ d->do_drops = config_get_boolean_ondemand(var_name, "drops", do_drops);
+ d->do_fifo = config_get_boolean_ondemand(var_name, "fifo", do_fifo);
d->do_compressed = config_get_boolean_ondemand(var_name, "compressed", do_compressed);
- d->do_events = config_get_boolean_ondemand(var_name, "events", do_events);
+ d->do_events = config_get_boolean_ondemand(var_name, "events", do_events);
}
if(unlikely(!d->enabled))
continue;
- d->rbytes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
- d->rpackets = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
- d->rerrors = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
- d->rdrops = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
- d->rfifo = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
- d->rframe = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
- d->rcompressed = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
- d->rmulticast = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
-
- d->tbytes = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
- d->tpackets = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
- d->terrors = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
- d->tdrops = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
- d->tfifo = strtoull(procfile_lineword(ff, l, 13), NULL, 10);
- d->tcollisions = strtoull(procfile_lineword(ff, l, 14), NULL, 10);
- d->tcarrier = strtoull(procfile_lineword(ff, l, 15), NULL, 10);
- d->tcompressed = strtoull(procfile_lineword(ff, l, 16), NULL, 10);
+ if(likely(d->do_bandwidth != CONFIG_ONDEMAND_NO)) {
+ d->rbytes = str2kernel_uint_t(procfile_lineword(ff, l, 1));
+ d->tbytes = str2kernel_uint_t(procfile_lineword(ff, l, 9));
+ }
+
+ if(likely(d->do_packets != CONFIG_ONDEMAND_NO)) {
+ d->rpackets = str2kernel_uint_t(procfile_lineword(ff, l, 2));
+ d->rmulticast = str2kernel_uint_t(procfile_lineword(ff, l, 8));
+ d->tpackets = str2kernel_uint_t(procfile_lineword(ff, l, 10));
+ }
+
+ if(likely(d->do_errors != CONFIG_ONDEMAND_NO)) {
+ d->rerrors = str2kernel_uint_t(procfile_lineword(ff, l, 3));
+ d->terrors = str2kernel_uint_t(procfile_lineword(ff, l, 11));
+ }
+
+ if(likely(d->do_drops != CONFIG_ONDEMAND_NO)) {
+ d->rdrops = str2kernel_uint_t(procfile_lineword(ff, l, 4));
+ d->tdrops = str2kernel_uint_t(procfile_lineword(ff, l, 12));
+ }
+
+ if(likely(d->do_fifo != CONFIG_ONDEMAND_NO)) {
+ d->rfifo = str2kernel_uint_t(procfile_lineword(ff, l, 5));
+ d->tfifo = str2kernel_uint_t(procfile_lineword(ff, l, 13));
+ }
+
+ if(likely(d->do_compressed != CONFIG_ONDEMAND_NO)) {
+ d->rcompressed = str2kernel_uint_t(procfile_lineword(ff, l, 7));
+ d->tcompressed = str2kernel_uint_t(procfile_lineword(ff, l, 16));
+ }
+
+ if(likely(d->do_events != CONFIG_ONDEMAND_NO)) {
+ d->rframe = str2kernel_uint_t(procfile_lineword(ff, l, 6));
+ d->tcollisions = str2kernel_uint_t(procfile_lineword(ff, l, 14));
+ d->tcarrier = str2kernel_uint_t(procfile_lineword(ff, l, 15));
+ }
// --------------------------------------------------------------------
if(unlikely(!d->st_bandwidth)) {
d->st_bandwidth = rrdset_find_bytype("net", d->name);
- if(!d->st_bandwidth) {
+ if(!d->st_bandwidth)
d->st_bandwidth = rrdset_create("net", d->name, NULL, d->name, "net.net", "Bandwidth", "kilobits/s", 7000, update_every, RRDSET_TYPE_AREA);
- d->rd_rbytes = rrddim_add(d->st_bandwidth, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
- d->rd_tbytes = rrddim_add(d->st_bandwidth, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
- }
+
+ d->rd_rbytes = rrddim_add(d->st_bandwidth, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
+ d->rd_tbytes = rrddim_add(d->st_bandwidth, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
}
else rrdset_next(d->st_bandwidth);
if(unlikely(!d->st_packets)) {
d->st_packets = rrdset_find_bytype("net_packets", d->name);
- if(!d->st_packets) {
+ if(!d->st_packets)
d->st_packets = rrdset_create("net_packets", d->name, NULL, d->name, "net.packets", "Packets", "packets/s", 7001, update_every, RRDSET_TYPE_LINE);
- d->st_packets->isdetail = 1;
- d->rd_rpackets = rrddim_add(d->st_packets, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
- d->rd_tpackets = rrddim_add(d->st_packets, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
- d->rd_rmulticast = rrddim_add(d->st_packets, "multicast", NULL, 1, 1, RRDDIM_INCREMENTAL);
- }
+ d->st_packets->isdetail = 1;
+
+ d->rd_rpackets = rrddim_add(d->st_packets, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
+ d->rd_tpackets = rrddim_add(d->st_packets, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
+ d->rd_rmulticast = rrddim_add(d->st_packets, "multicast", NULL, 1, 1, RRDDIM_INCREMENTAL);
}
else rrdset_next(d->st_packets);
if(unlikely(!d->st_errors)) {
d->st_errors = rrdset_find_bytype("net_errors", d->name);
- if(!d->st_errors) {
+ if(!d->st_errors)
d->st_errors = rrdset_create("net_errors", d->name, NULL, d->name, "net.errors", "Interface Errors", "errors/s", 7002, update_every, RRDSET_TYPE_LINE);
- d->st_errors->isdetail = 1;
- d->rd_rerrors = rrddim_add(d->st_errors, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
- d->rd_terrors = rrddim_add(d->st_errors, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
- }
+ d->st_errors->isdetail = 1;
+
+ d->rd_rerrors = rrddim_add(d->st_errors, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
+ d->rd_terrors = rrddim_add(d->st_errors, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
}
else rrdset_next(d->st_errors);
if(unlikely(!d->st_drops)) {
d->st_drops = rrdset_find_bytype("net_drops", d->name);
- if(!d->st_drops) {
+ if(!d->st_drops)
d->st_drops = rrdset_create("net_drops", d->name, NULL, d->name, "net.drops", "Interface Drops", "drops/s", 7003, update_every, RRDSET_TYPE_LINE);
- d->st_drops->isdetail = 1;
- d->rd_rdrops = rrddim_add(d->st_drops, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
- d->rd_tdrops = rrddim_add(d->st_drops, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
- }
+ d->st_drops->isdetail = 1;
+
+ d->rd_rdrops = rrddim_add(d->st_drops, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
+ d->rd_tdrops = rrddim_add(d->st_drops, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
}
else rrdset_next(d->st_drops);
if(unlikely(!d->st_fifo)) {
d->st_fifo = rrdset_find_bytype("net_fifo", d->name);
- if(!d->st_fifo) {
+ if(!d->st_fifo)
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);
- d->st_fifo->isdetail = 1;
- d->rd_rfifo = rrddim_add(d->st_fifo, "receive", NULL, 1, 1, RRDDIM_INCREMENTAL);
- d->rd_tfifo = rrddim_add(d->st_fifo, "transmit", NULL, -1, 1, RRDDIM_INCREMENTAL);
- }
+ d->st_fifo->isdetail = 1;
+
+ d->rd_rfifo = rrddim_add(d->st_fifo, "receive", NULL, 1, 1, RRDDIM_INCREMENTAL);
+ d->rd_tfifo = rrddim_add(d->st_fifo, "transmit", NULL, -1, 1, RRDDIM_INCREMENTAL);
}
else rrdset_next(d->st_fifo);
if(d->do_compressed == CONFIG_ONDEMAND_YES) {
if(unlikely(!d->st_compressed)) {
d->st_compressed = rrdset_find_bytype("net_compressed", d->name);
- if(!d->st_compressed) {
+ if(!d->st_compressed)
d->st_compressed = rrdset_create("net_compressed", d->name, NULL, d->name, "net.compressed", "Compressed Packets", "packets/s", 7005, update_every, RRDSET_TYPE_LINE);
- d->st_compressed->isdetail = 1;
- d->rd_rcompressed = rrddim_add(d->st_compressed, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
- d->rd_tcompressed = rrddim_add(d->st_compressed, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
- }
+ d->st_compressed->isdetail = 1;
+
+ d->rd_rcompressed = rrddim_add(d->st_compressed, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
+ d->rd_tcompressed = rrddim_add(d->st_compressed, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
}
else rrdset_next(d->st_compressed);
if(d->do_events == CONFIG_ONDEMAND_YES) {
if(unlikely(!d->st_events)) {
d->st_events = rrdset_find_bytype("net_events", d->name);
- if(!d->st_events) {
+ if(!d->st_events)
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);
- d->st_events->isdetail = 1;
- d->rd_rframe = rrddim_add(d->st_events, "frames", NULL, 1, 1, RRDDIM_INCREMENTAL);
- d->rd_tcollisions = rrddim_add(d->st_events, "collisions", NULL, -1, 1, RRDDIM_INCREMENTAL);
- d->rd_tcarrier = rrddim_add(d->st_events, "carrier", NULL, -1, 1, RRDDIM_INCREMENTAL);
- }
+ d->st_events->isdetail = 1;
+
+ d->rd_rframe = rrddim_add(d->st_events, "frames", NULL, 1, 1, RRDDIM_INCREMENTAL);
+ d->rd_tcollisions = rrddim_add(d->st_events, "collisions", NULL, -1, 1, RRDDIM_INCREMENTAL);
+ d->rd_tcarrier = rrddim_add(d->st_events, "carrier", NULL, -1, 1, RRDDIM_INCREMENTAL);
}
else rrdset_next(d->st_events);