10 #include "plugin_proc.h"
12 int do_proc_net_netstat(int update_every, unsigned long long dt) {
13 static int do_bandwidth = -1, do_inerrors = -1, do_mcast = -1, do_bcast = -1, do_mcast_p = -1, do_bcast_p = -1;
14 static procfile *ff = NULL;
16 if(do_bandwidth == -1) do_bandwidth = config_get_boolean("plugin:proc:/proc/net/netstat", "bandwidth", 1);
17 if(do_inerrors == -1) do_inerrors = config_get_boolean("plugin:proc:/proc/net/netstat", "input errors", 1);
18 if(do_mcast == -1) do_mcast = config_get_boolean("plugin:proc:/proc/net/netstat", "multicast bandwidth", 1);
19 if(do_bcast == -1) do_bcast = config_get_boolean("plugin:proc:/proc/net/netstat", "broadcast bandwidth", 1);
20 if(do_mcast_p == -1) do_mcast_p = config_get_boolean("plugin:proc:/proc/net/netstat", "multicast packets", 1);
21 if(do_bcast_p == -1) do_bcast_p = config_get_boolean("plugin:proc:/proc/net/netstat", "broadcast packets", 1);
25 if(!ff) ff = procfile_open("/proc/net/netstat", " \t:");
28 ff = procfile_readall(ff);
29 if(!ff) return 0; // we return 0, so that we will retry to open it next time
31 uint32_t lines = procfile_lines(ff), l;
34 for(l = 0; l < lines ;l++) {
35 if(strcmp(procfile_lineword(ff, l, 0), "IpExt") == 0) {
36 l++; // we need the next line
38 if(strcmp(procfile_lineword(ff, l, 0), "IpExt") != 0) {
39 error("Cannot read IpExt line from /proc/net/netstat.");
42 words = procfile_linewords(ff, l);
44 error("Cannot read /proc/net/netstat IpExt line. Expected 12 params, read %d.", words);
49 InNoRoutes = 0, InTruncatedPkts = 0,
50 InOctets = 0, InMcastPkts = 0, InBcastPkts = 0, InMcastOctets = 0, InBcastOctets = 0,
51 OutOctets = 0, OutMcastPkts = 0, OutBcastPkts = 0, OutMcastOctets = 0, OutBcastOctets = 0;
53 InNoRoutes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
54 InTruncatedPkts = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
55 InMcastPkts = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
56 OutMcastPkts = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
57 InBcastPkts = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
58 OutBcastPkts = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
59 InOctets = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
60 OutOctets = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
61 InMcastOctets = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
62 OutMcastOctets = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
63 InBcastOctets = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
64 OutBcastOctets = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
68 // --------------------------------------------------------------------
71 st = rrd_stats_find("system.ipv4");
73 st = rrd_stats_create("system", "ipv4", NULL, "ipv4", "IPv4 Bandwidth", "kilobits/s", 2000, update_every, CHART_TYPE_AREA);
75 rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
76 rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
78 else rrd_stats_next(st);
80 rrd_stats_dimension_set(st, "sent", OutOctets);
81 rrd_stats_dimension_set(st, "received", InOctets);
85 // --------------------------------------------------------------------
88 st = rrd_stats_find("ipv4.inerrors");
90 st = rrd_stats_create("ipv4", "inerrors", NULL, "ipv4", "IPv4 Input Errors", "packets/s", 4000, update_every, CHART_TYPE_LINE);
93 rrd_stats_dimension_add(st, "noroutes", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
94 rrd_stats_dimension_add(st, "trunkated", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
96 else rrd_stats_next(st);
98 rrd_stats_dimension_set(st, "noroutes", InNoRoutes);
99 rrd_stats_dimension_set(st, "trunkated", InTruncatedPkts);
103 // --------------------------------------------------------------------
106 st = rrd_stats_find("ipv4.mcast");
108 st = rrd_stats_create("ipv4", "mcast", NULL, "ipv4", "IPv4 Multicast Bandwidth", "kilobits/s", 9000, update_every, CHART_TYPE_AREA);
111 rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
112 rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
114 else rrd_stats_next(st);
116 rrd_stats_dimension_set(st, "sent", OutMcastOctets);
117 rrd_stats_dimension_set(st, "received", InMcastOctets);
121 // --------------------------------------------------------------------
124 st = rrd_stats_find("ipv4.bcast");
126 st = rrd_stats_create("ipv4", "bcast", NULL, "ipv4", "IPv4 Broadcast Bandwidth", "kilobits/s", 8000, update_every, CHART_TYPE_AREA);
129 rrd_stats_dimension_add(st, "received", NULL, 8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
130 rrd_stats_dimension_add(st, "sent", NULL, -8, 1024 * update_every, RRD_DIMENSION_INCREMENTAL);
132 else rrd_stats_next(st);
134 rrd_stats_dimension_set(st, "sent", OutBcastOctets);
135 rrd_stats_dimension_set(st, "received", InBcastOctets);
139 // --------------------------------------------------------------------
142 st = rrd_stats_find("ipv4.mcastpkts");
144 st = rrd_stats_create("ipv4", "mcastpkts", NULL, "ipv4", "IPv4 Multicast Packets", "packets/s", 9500, update_every, CHART_TYPE_LINE);
147 rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
148 rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
150 else rrd_stats_next(st);
152 rrd_stats_dimension_set(st, "sent", OutMcastPkts);
153 rrd_stats_dimension_set(st, "received", InMcastPkts);
157 // --------------------------------------------------------------------
160 st = rrd_stats_find("ipv4.bcastpkts");
162 st = rrd_stats_create("ipv4", "bcastpkts", NULL, "ipv4", "IPv4 Broadcast Packets", "packets/s", 8500, update_every, CHART_TYPE_LINE);
165 rrd_stats_dimension_add(st, "received", NULL, 1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
166 rrd_stats_dimension_add(st, "sent", NULL, -1, 1 * update_every, RRD_DIMENSION_INCREMENTAL);
168 else rrd_stats_next(st);
170 rrd_stats_dimension_set(st, "sent", OutBcastPkts);
171 rrd_stats_dimension_set(st, "received", InBcastPkts);