11 #include "plugin_proc.h"
13 int do_proc_net_netstat(int update_every, unsigned long long dt) {
14 static int do_bandwidth = -1, do_inerrors = -1, do_mcast = -1, do_bcast = -1, do_mcast_p = -1, do_bcast_p = -1;
15 static procfile *ff = NULL;
17 if(do_bandwidth == -1) do_bandwidth = config_get_boolean("plugin:proc:/proc/net/netstat", "bandwidth", 1);
18 if(do_inerrors == -1) do_inerrors = config_get_boolean("plugin:proc:/proc/net/netstat", "input errors", 1);
19 if(do_mcast == -1) do_mcast = config_get_boolean("plugin:proc:/proc/net/netstat", "multicast bandwidth", 1);
20 if(do_bcast == -1) do_bcast = config_get_boolean("plugin:proc:/proc/net/netstat", "broadcast bandwidth", 1);
21 if(do_mcast_p == -1) do_mcast_p = config_get_boolean("plugin:proc:/proc/net/netstat", "multicast packets", 1);
22 if(do_bcast_p == -1) do_bcast_p = config_get_boolean("plugin:proc:/proc/net/netstat", "broadcast packets", 1);
27 char filename[FILENAME_MAX + 1];
28 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/netstat");
29 ff = procfile_open(config_get("plugin:proc:/proc/net/netstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
33 ff = procfile_readall(ff);
34 if(!ff) return 0; // we return 0, so that we will retry to open it next time
36 uint32_t lines = procfile_lines(ff), l;
39 for(l = 0; l < lines ;l++) {
40 if(strcmp(procfile_lineword(ff, l, 0), "IpExt") == 0) {
41 l++; // we need the next line
43 if(strcmp(procfile_lineword(ff, l, 0), "IpExt") != 0) {
44 error("Cannot read IpExt line from /proc/net/netstat.");
47 words = procfile_linewords(ff, l);
49 error("Cannot read /proc/net/netstat IpExt line. Expected 12 params, read %d.", words);
54 InNoRoutes = 0, InTruncatedPkts = 0,
55 InOctets = 0, InMcastPkts = 0, InBcastPkts = 0, InMcastOctets = 0, InBcastOctets = 0,
56 OutOctets = 0, OutMcastPkts = 0, OutBcastPkts = 0, OutMcastOctets = 0, OutBcastOctets = 0;
58 InNoRoutes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
59 InTruncatedPkts = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
60 InMcastPkts = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
61 OutMcastPkts = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
62 InBcastPkts = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
63 OutBcastPkts = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
64 InOctets = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
65 OutOctets = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
66 InMcastOctets = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
67 OutMcastOctets = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
68 InBcastOctets = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
69 OutBcastOctets = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
73 // --------------------------------------------------------------------
76 st = rrdset_find("system.ipv4");
78 st = rrdset_create("system", "ipv4", NULL, "ipv4", "IPv4 Bandwidth", "kilobits/s", 2000, update_every, RRDSET_TYPE_AREA);
80 rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
81 rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
85 rrddim_set(st, "sent", OutOctets);
86 rrddim_set(st, "received", InOctets);
90 // --------------------------------------------------------------------
93 st = rrdset_find("ipv4.inerrors");
95 st = rrdset_create("ipv4", "inerrors", NULL, "ipv4", "IPv4 Input Errors", "packets/s", 4000, update_every, RRDSET_TYPE_LINE);
98 rrddim_add(st, "noroutes", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
99 rrddim_add(st, "trunkated", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
101 else rrdset_next(st);
103 rrddim_set(st, "noroutes", InNoRoutes);
104 rrddim_set(st, "trunkated", InTruncatedPkts);
108 // --------------------------------------------------------------------
111 st = rrdset_find("ipv4.mcast");
113 st = rrdset_create("ipv4", "mcast", NULL, "ipv4", "IPv4 Multicast Bandwidth", "kilobits/s", 9000, update_every, RRDSET_TYPE_AREA);
116 rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
117 rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
119 else rrdset_next(st);
121 rrddim_set(st, "sent", OutMcastOctets);
122 rrddim_set(st, "received", InMcastOctets);
126 // --------------------------------------------------------------------
129 st = rrdset_find("ipv4.bcast");
131 st = rrdset_create("ipv4", "bcast", NULL, "ipv4", "IPv4 Broadcast Bandwidth", "kilobits/s", 8000, update_every, RRDSET_TYPE_AREA);
134 rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
135 rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
137 else rrdset_next(st);
139 rrddim_set(st, "sent", OutBcastOctets);
140 rrddim_set(st, "received", InBcastOctets);
144 // --------------------------------------------------------------------
147 st = rrdset_find("ipv4.mcastpkts");
149 st = rrdset_create("ipv4", "mcastpkts", NULL, "ipv4", "IPv4 Multicast Packets", "packets/s", 9500, update_every, RRDSET_TYPE_LINE);
152 rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
153 rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
155 else rrdset_next(st);
157 rrddim_set(st, "sent", OutMcastPkts);
158 rrddim_set(st, "received", InMcastPkts);
162 // --------------------------------------------------------------------
165 st = rrdset_find("ipv4.bcastpkts");
167 st = rrdset_create("ipv4", "bcastpkts", NULL, "ipv4", "IPv4 Broadcast Packets", "packets/s", 8500, update_every, RRDSET_TYPE_LINE);
170 rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
171 rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
173 else rrdset_next(st);
175 rrddim_set(st, "sent", OutBcastPkts);
176 rrddim_set(st, "received", InBcastPkts);