3 int do_proc_net_netstat(int update_every, unsigned long long dt) {
4 static int do_bandwidth = -1, do_inerrors = -1, do_mcast = -1, do_bcast = -1, do_mcast_p = -1, do_bcast_p = -1;
5 static procfile *ff = NULL;
7 if(do_bandwidth == -1) do_bandwidth = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "bandwidth", CONFIG_ONDEMAND_ONDEMAND);
8 if(do_inerrors == -1) do_inerrors = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "input errors", CONFIG_ONDEMAND_ONDEMAND);
9 if(do_mcast == -1) do_mcast = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "multicast bandwidth", CONFIG_ONDEMAND_ONDEMAND);
10 if(do_bcast == -1) do_bcast = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "broadcast bandwidth", CONFIG_ONDEMAND_ONDEMAND);
11 if(do_mcast_p == -1) do_mcast_p = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "multicast packets", CONFIG_ONDEMAND_ONDEMAND);
12 if(do_bcast_p == -1) do_bcast_p = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "broadcast packets", CONFIG_ONDEMAND_ONDEMAND);
17 char filename[FILENAME_MAX + 1];
18 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/netstat");
19 ff = procfile_open(config_get("plugin:proc:/proc/net/netstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
23 ff = procfile_readall(ff);
24 if(!ff) return 0; // we return 0, so that we will retry to open it next time
26 uint32_t lines = procfile_lines(ff), l;
29 for(l = 0; l < lines ;l++) {
30 if(strcmp(procfile_lineword(ff, l, 0), "IpExt") == 0) {
31 l++; // we need the next line
33 if(strcmp(procfile_lineword(ff, l, 0), "IpExt") != 0) {
34 error("Cannot read IpExt line from /proc/net/netstat.");
37 words = procfile_linewords(ff, l);
39 error("Cannot read /proc/net/netstat IpExt line. Expected 12 params, read %u.", words);
44 InNoRoutes = 0, InTruncatedPkts = 0,
45 InOctets = 0, InMcastPkts = 0, InBcastPkts = 0, InMcastOctets = 0, InBcastOctets = 0,
46 OutOctets = 0, OutMcastPkts = 0, OutBcastPkts = 0, OutMcastOctets = 0, OutBcastOctets = 0;
48 InNoRoutes = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
49 InTruncatedPkts = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
50 InMcastPkts = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
51 OutMcastPkts = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
52 InBcastPkts = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
53 OutBcastPkts = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
54 InOctets = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
55 OutOctets = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
56 InMcastOctets = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
57 OutMcastOctets = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
58 InBcastOctets = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
59 OutBcastOctets = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
63 // --------------------------------------------------------------------
65 if(do_bandwidth == CONFIG_ONDEMAND_YES || (do_bandwidth == CONFIG_ONDEMAND_ONDEMAND && (InOctets || OutOctets))) {
66 do_bandwidth = CONFIG_ONDEMAND_YES;
67 st = rrdset_find("system.ipv4");
69 st = rrdset_create("system", "ipv4", NULL, "network", NULL, "IPv4 Bandwidth", "kilobits/s", 500, update_every, RRDSET_TYPE_AREA);
71 rrddim_add(st, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
72 rrddim_add(st, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
76 rrddim_set(st, "sent", OutOctets);
77 rrddim_set(st, "received", InOctets);
81 // --------------------------------------------------------------------
83 if(do_inerrors == CONFIG_ONDEMAND_YES || (do_inerrors == CONFIG_ONDEMAND_ONDEMAND && (InNoRoutes || InTruncatedPkts))) {
84 do_inerrors = CONFIG_ONDEMAND_YES;
85 st = rrdset_find("ipv4.inerrors");
87 st = rrdset_create("ipv4", "inerrors", NULL, "errors", NULL, "IPv4 Input Errors", "packets/s", 4000, update_every, RRDSET_TYPE_LINE);
90 rrddim_add(st, "noroutes", NULL, 1, 1, RRDDIM_INCREMENTAL);
91 rrddim_add(st, "truncated", NULL, 1, 1, RRDDIM_INCREMENTAL);
95 rrddim_set(st, "noroutes", InNoRoutes);
96 rrddim_set(st, "truncated", InTruncatedPkts);
100 // --------------------------------------------------------------------
102 if(do_mcast == CONFIG_ONDEMAND_YES || (do_mcast == CONFIG_ONDEMAND_ONDEMAND && (InMcastOctets || OutMcastOctets))) {
103 do_mcast = CONFIG_ONDEMAND_YES;
104 st = rrdset_find("ipv4.mcast");
106 st = rrdset_create("ipv4", "mcast", NULL, "multicast", NULL, "IPv4 Multicast Bandwidth", "kilobits/s", 9000, update_every, RRDSET_TYPE_AREA);
109 rrddim_add(st, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
110 rrddim_add(st, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
112 else rrdset_next(st);
114 rrddim_set(st, "sent", OutMcastOctets);
115 rrddim_set(st, "received", InMcastOctets);
119 // --------------------------------------------------------------------
121 if(do_bcast == CONFIG_ONDEMAND_YES || (do_bcast == CONFIG_ONDEMAND_ONDEMAND && (InBcastOctets || OutBcastOctets))) {
122 do_bcast = CONFIG_ONDEMAND_YES;
123 st = rrdset_find("ipv4.bcast");
125 st = rrdset_create("ipv4", "bcast", NULL, "broadcast", NULL, "IPv4 Broadcast Bandwidth", "kilobits/s", 8000, update_every, RRDSET_TYPE_AREA);
128 rrddim_add(st, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
129 rrddim_add(st, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
131 else rrdset_next(st);
133 rrddim_set(st, "sent", OutBcastOctets);
134 rrddim_set(st, "received", InBcastOctets);
138 // --------------------------------------------------------------------
140 if(do_mcast_p == CONFIG_ONDEMAND_YES || (do_mcast_p == CONFIG_ONDEMAND_ONDEMAND && (InMcastPkts || OutMcastPkts))) {
141 do_mcast_p = CONFIG_ONDEMAND_YES;
142 st = rrdset_find("ipv4.mcastpkts");
144 st = rrdset_create("ipv4", "mcastpkts", NULL, "multicast", NULL, "IPv4 Multicast Packets", "packets/s", 9500, update_every, RRDSET_TYPE_LINE);
147 rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
148 rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
150 else rrdset_next(st);
152 rrddim_set(st, "sent", OutMcastPkts);
153 rrddim_set(st, "received", InMcastPkts);
157 // --------------------------------------------------------------------
159 if(do_bcast_p == CONFIG_ONDEMAND_YES || (do_bcast_p == CONFIG_ONDEMAND_ONDEMAND && (InBcastPkts || OutBcastPkts))) {
160 do_bcast_p = CONFIG_ONDEMAND_YES;
161 st = rrdset_find("ipv4.bcastpkts");
163 st = rrdset_create("ipv4", "bcastpkts", NULL, "broadcast", NULL, "IPv4 Broadcast Packets", "packets/s", 8500, update_every, RRDSET_TYPE_LINE);
166 rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
167 rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
169 else rrdset_next(st);
171 rrddim_set(st, "sent", OutBcastPkts);
172 rrddim_set(st, "received", InBcastPkts);