10 #include "appconfig.h"
13 #include "plugin_proc.h"
15 int do_proc_net_netstat(int update_every, unsigned long long dt) {
16 static int do_bandwidth = -1, do_inerrors = -1, do_mcast = -1, do_bcast = -1, do_mcast_p = -1, do_bcast_p = -1;
17 static procfile *ff = NULL;
19 if(do_bandwidth == -1) do_bandwidth = config_get_boolean("plugin:proc:/proc/net/netstat", "bandwidth", 1);
20 if(do_inerrors == -1) do_inerrors = config_get_boolean("plugin:proc:/proc/net/netstat", "input errors", 1);
21 if(do_mcast == -1) do_mcast = config_get_boolean("plugin:proc:/proc/net/netstat", "multicast bandwidth", 1);
22 if(do_bcast == -1) do_bcast = config_get_boolean("plugin:proc:/proc/net/netstat", "broadcast bandwidth", 1);
23 if(do_mcast_p == -1) do_mcast_p = config_get_boolean("plugin:proc:/proc/net/netstat", "multicast packets", 1);
24 if(do_bcast_p == -1) do_bcast_p = config_get_boolean("plugin:proc:/proc/net/netstat", "broadcast packets", 1);
29 char filename[FILENAME_MAX + 1];
30 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/netstat");
31 ff = procfile_open(config_get("plugin:proc:/proc/net/netstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
35 ff = procfile_readall(ff);
36 if(!ff) return 0; // we return 0, so that we will retry to open it next time
38 uint32_t lines = procfile_lines(ff), l;
41 for(l = 0; l < lines ;l++) {
42 if(strcmp(procfile_lineword(ff, l, 0), "IpExt") == 0) {
43 l++; // we need the next line
45 if(strcmp(procfile_lineword(ff, l, 0), "IpExt") != 0) {
46 error("Cannot read IpExt line from /proc/net/netstat.");
49 words = procfile_linewords(ff, l);
51 error("Cannot read /proc/net/netstat IpExt line. Expected 12 params, read %d.", words);
56 InNoRoutes = 0, InTruncatedPkts = 0,
57 InOctets = 0, InMcastPkts = 0, InBcastPkts = 0, InMcastOctets = 0, InBcastOctets = 0,
58 OutOctets = 0, OutMcastPkts = 0, OutBcastPkts = 0, OutMcastOctets = 0, OutBcastOctets = 0;
60 InNoRoutes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
61 InTruncatedPkts = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
62 InMcastPkts = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
63 OutMcastPkts = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
64 InBcastPkts = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
65 OutBcastPkts = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
66 InOctets = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
67 OutOctets = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
68 InMcastOctets = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
69 OutMcastOctets = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
70 InBcastOctets = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
71 OutBcastOctets = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
75 // --------------------------------------------------------------------
78 st = rrdset_find("system.ipv4");
80 st = rrdset_create("system", "ipv4", NULL, "ipv4", "IPv4 Bandwidth", "kilobits/s", 2000, update_every, RRDSET_TYPE_AREA);
82 rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
83 rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
87 rrddim_set(st, "sent", OutOctets);
88 rrddim_set(st, "received", InOctets);
92 // --------------------------------------------------------------------
95 st = rrdset_find("ipv4.inerrors");
97 st = rrdset_create("ipv4", "inerrors", NULL, "ipv4", "IPv4 Input Errors", "packets/s", 4000, update_every, RRDSET_TYPE_LINE);
100 rrddim_add(st, "noroutes", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
101 rrddim_add(st, "trunkated", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
103 else rrdset_next(st);
105 rrddim_set(st, "noroutes", InNoRoutes);
106 rrddim_set(st, "trunkated", InTruncatedPkts);
110 // --------------------------------------------------------------------
113 st = rrdset_find("ipv4.mcast");
115 st = rrdset_create("ipv4", "mcast", NULL, "ipv4", "IPv4 Multicast Bandwidth", "kilobits/s", 9000, update_every, RRDSET_TYPE_AREA);
118 rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
119 rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
121 else rrdset_next(st);
123 rrddim_set(st, "sent", OutMcastOctets);
124 rrddim_set(st, "received", InMcastOctets);
128 // --------------------------------------------------------------------
131 st = rrdset_find("ipv4.bcast");
133 st = rrdset_create("ipv4", "bcast", NULL, "ipv4", "IPv4 Broadcast Bandwidth", "kilobits/s", 8000, update_every, RRDSET_TYPE_AREA);
136 rrddim_add(st, "received", NULL, 8, 1024 * update_every, RRDDIM_INCREMENTAL);
137 rrddim_add(st, "sent", NULL, -8, 1024 * update_every, RRDDIM_INCREMENTAL);
139 else rrdset_next(st);
141 rrddim_set(st, "sent", OutBcastOctets);
142 rrddim_set(st, "received", InBcastOctets);
146 // --------------------------------------------------------------------
149 st = rrdset_find("ipv4.mcastpkts");
151 st = rrdset_create("ipv4", "mcastpkts", NULL, "ipv4", "IPv4 Multicast Packets", "packets/s", 9500, update_every, RRDSET_TYPE_LINE);
154 rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
155 rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
157 else rrdset_next(st);
159 rrddim_set(st, "sent", OutMcastPkts);
160 rrddim_set(st, "received", InMcastPkts);
164 // --------------------------------------------------------------------
167 st = rrdset_find("ipv4.bcastpkts");
169 st = rrdset_create("ipv4", "bcastpkts", NULL, "ipv4", "IPv4 Broadcast Packets", "packets/s", 8500, update_every, RRDSET_TYPE_LINE);
172 rrddim_add(st, "received", NULL, 1, 1 * update_every, RRDDIM_INCREMENTAL);
173 rrddim_add(st, "sent", NULL, -1, 1 * update_every, RRDDIM_INCREMENTAL);
175 else rrdset_next(st);
177 rrddim_set(st, "sent", OutBcastPkts);
178 rrddim_set(st, "received", InBcastPkts);