8 #include "plugin_proc.h"
10 int do_proc_net_dev(int update_every, unsigned long long dt) {
11 static procfile *ff = NULL;
12 static int enable_new_interfaces = -1;
13 static int do_bandwidth = -1, do_packets = -1, do_errors = -1, do_drops = -1, do_fifo = -1, do_compressed = -1, do_events = -1;
17 if(!ff) ff = procfile_open("/proc/net/dev", " \t,:|");
20 ff = procfile_readall(ff);
21 if(!ff) return 0; // we return 0, so that we will retry to open it next time
23 if(enable_new_interfaces == -1) enable_new_interfaces = config_get_boolean("plugin:proc:/proc/net/dev", "enable new interfaces detected at runtime", 1);
25 if(do_bandwidth == -1) do_bandwidth = config_get_boolean("plugin:proc:/proc/net/dev", "bandwidth for all interfaces", 1);
26 if(do_packets == -1) do_packets = config_get_boolean("plugin:proc:/proc/net/dev", "packets for all interfaces", 1);
27 if(do_errors == -1) do_errors = config_get_boolean("plugin:proc:/proc/net/dev", "errors for all interfaces", 1);
28 if(do_drops == -1) do_drops = config_get_boolean("plugin:proc:/proc/net/dev", "drops for all interfaces", 1);
29 if(do_fifo == -1) do_fifo = config_get_boolean("plugin:proc:/proc/net/dev", "fifo for all interfaces", 1);
30 if(do_compressed == -1) do_compressed = config_get_boolean("plugin:proc:/proc/net/dev", "compressed packets for all interfaces", 1);
31 if(do_events == -1) do_events = config_get_boolean("plugin:proc:/proc/net/dev", "frames, collisions, carrier coutners for all interfaces", 1);
33 uint32_t lines = procfile_lines(ff), l;
37 unsigned long long rbytes, rpackets, rerrors, rdrops, rfifo, rframe, rcompressed, rmulticast;
38 unsigned long long tbytes, tpackets, terrors, tdrops, tfifo, tcollisions, tcarrier, tcompressed;
40 for(l = 2; l < lines ;l++) {
41 words = procfile_linewords(ff, l);
42 if(words < 17) continue;
44 iface = procfile_lineword(ff, l, 0);
46 rbytes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
47 rpackets = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
48 rerrors = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
49 rdrops = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
50 rfifo = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
51 rframe = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
52 rcompressed = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
53 rmulticast = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
55 tbytes = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
56 tpackets = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
57 terrors = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
58 tdrops = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
59 tfifo = strtoull(procfile_lineword(ff, l, 13), NULL, 10);
60 tcollisions = strtoull(procfile_lineword(ff, l, 14), NULL, 10);
61 tcarrier = strtoull(procfile_lineword(ff, l, 15), NULL, 10);
62 tcompressed = strtoull(procfile_lineword(ff, l, 16), NULL, 10);
65 char var_name[4096 + 1];
66 snprintf(var_name, 4096, "interface %s", iface);
67 if(!config_get_boolean("plugin:proc:/proc/net/dev", var_name, enable_new_interfaces)) continue;
72 // --------------------------------------------------------------------
75 st = rrd_stats_find_bytype("net", iface);
77 st = rrd_stats_create("net", iface, NULL, iface, "Bandwidth", "kilobits/s", 1000, update_every, CHART_TYPE_AREA);
79 rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
80 rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
82 else rrd_stats_next(st);
84 rrd_stats_dimension_set(st, "received", rbytes);
85 rrd_stats_dimension_set(st, "sent", tbytes);
89 // --------------------------------------------------------------------
92 st = rrd_stats_find_bytype("net_packets", iface);
94 st = rrd_stats_create("net_packets", iface, NULL, iface, "Packets", "packets/s", 1001, update_every, CHART_TYPE_LINE);
97 rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
98 rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
99 rrd_stats_dimension_add(st, "multicast", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
101 else rrd_stats_next(st);
103 rrd_stats_dimension_set(st, "received", rpackets);
104 rrd_stats_dimension_set(st, "sent", tpackets);
105 rrd_stats_dimension_set(st, "multicast", rmulticast);
109 // --------------------------------------------------------------------
112 st = rrd_stats_find_bytype("net_errors", iface);
114 st = rrd_stats_create("net_errors", iface, NULL, iface, "Interface Errors", "errors/s", 1002, update_every, CHART_TYPE_LINE);
117 rrd_stats_dimension_add(st, "inbound", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
118 rrd_stats_dimension_add(st, "outbound", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
120 else rrd_stats_next(st);
122 rrd_stats_dimension_set(st, "inbound", rerrors);
123 rrd_stats_dimension_set(st, "outbound", terrors);
127 // --------------------------------------------------------------------
130 st = rrd_stats_find_bytype("net_drops", iface);
132 st = rrd_stats_create("net_drops", iface, NULL, iface, "Interface Drops", "drops/s", 1003, update_every, CHART_TYPE_LINE);
135 rrd_stats_dimension_add(st, "inbound", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
136 rrd_stats_dimension_add(st, "outbound", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
138 else rrd_stats_next(st);
140 rrd_stats_dimension_set(st, "inbound", rdrops);
141 rrd_stats_dimension_set(st, "outbound", tdrops);
145 // --------------------------------------------------------------------
148 st = rrd_stats_find_bytype("net_fifo", iface);
150 st = rrd_stats_create("net_fifo", iface, NULL, iface, "Interface Queue", "packets", 1100, update_every, CHART_TYPE_LINE);
153 rrd_stats_dimension_add(st, "receive", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
154 rrd_stats_dimension_add(st, "transmit", NULL, -1, 1, RRD_DIMENSION_ABSOLUTE);
156 else rrd_stats_next(st);
158 rrd_stats_dimension_set(st, "receive", rfifo);
159 rrd_stats_dimension_set(st, "transmit", tfifo);
163 // --------------------------------------------------------------------
166 st = rrd_stats_find_bytype("net_compressed", iface);
168 st = rrd_stats_create("net_compressed", iface, NULL, iface, "Compressed Packets", "packets/s", 1200, update_every, CHART_TYPE_LINE);
171 rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
172 rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
174 else rrd_stats_next(st);
176 rrd_stats_dimension_set(st, "received", rcompressed);
177 rrd_stats_dimension_set(st, "sent", tcompressed);
181 // --------------------------------------------------------------------
184 st = rrd_stats_find_bytype("net_events", iface);
186 st = rrd_stats_create("net_events", iface, NULL, iface, "Network Interface Events", "events/s", 1200, update_every, CHART_TYPE_LINE);
189 rrd_stats_dimension_add(st, "frames", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
190 rrd_stats_dimension_add(st, "collisions", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
191 rrd_stats_dimension_add(st, "carrier", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
193 else rrd_stats_next(st);
195 rrd_stats_dimension_set(st, "frames", rframe);
196 rrd_stats_dimension_set(st, "collisions", tcollisions);
197 rrd_stats_dimension_set(st, "carrier", tcarrier);