2 +++ b/src/ipstatistics.c
5 + This Plugin is based opn the interface.c Plugin.
16 +#include <sys/types.h>
19 +#include "utils/cmds/putval.h"
20 +#include "utils/common/common.h"
22 +/* Copied from interface.c */
23 +static void ipstatistics_submit(const char *type, derive_t ip4rx,
24 + derive_t ip4tx, derive_t ip6rx, derive_t ip6tx) {
25 + value_list_t vl = VALUE_LIST_INIT;
26 + value_t values[] = {
34 + vl.values_len = STATIC_ARRAY_SIZE(values);
35 + sstrncpy(vl.plugin, "ipstatistics", sizeof(vl.plugin));
36 + sstrncpy(vl.plugin_instance, "all", sizeof(vl.plugin_instance));
37 + sstrncpy(vl.type, type, sizeof(vl.type));
39 + plugin_dispatch_values(&vl);
40 +} /* void if_submit */
42 +int ipstatistics_read() {
48 + derive_t ip4_in = 0;
49 + derive_t ip4_out = 0;
50 + derive_t ip6_in = 0;
51 + derive_t ip6_out = 0;
53 + if ((fh = fopen("/proc/net/snmp6", "r")) == NULL) {
54 + WARNING("ipstatistics plugin: try opening %s : fopen: %s", "/proc/net/snmp6",
59 + while (fgets(buffer, 1024, fh) != NULL) {
60 + numfields = strsplit(buffer, fields, 2);
65 + if (strcasecmp(fields[0], "Ip6OutOctets") == 0) {
66 + ip6_out = atoll(fields[1]);
69 + if (strcasecmp(fields[0], "Ip6InOctets") == 0) {
70 + ip6_in = atoll(fields[1]);
76 + if ((fh = fopen("/proc/net/netstat", "r")) == NULL) {
77 + WARNING("ipstatistics plugin: try opening %s : fopen: %s", "/proc/net/netstat",
82 + int count_ipext = 0;
83 + while (fgets(buffer, 1024, fh) != NULL) {
84 + numfields = strsplit(buffer, fields, 19);
89 + if (strcasecmp(fields[0], "IpExt:") == 0) {
91 + if (count_ipext == 2) {
92 + ip4_in = atoll(fields[7]);
93 + ip4_out = atoll(fields[8]);
100 + ipstatistics_submit("ip_stats_octets", ip4_in, ip4_out, ip6_in, ip6_out);
104 +void module_register(void) {
105 + plugin_register_read("ipstatistics", ipstatistics_read);
106 +} /* void module_register */
110 @@ -148,6 +148,7 @@ invocations value:DERIVE:0:U
111 io_octets rx:DERIVE:0:U, tx:DERIVE:0:U
112 io_ops read:DERIVE:0:U, write:DERIVE:0:U
113 io_packets rx:DERIVE:0:U, tx:DERIVE:0:U
114 +ip_stats_octets ip4rx:DERIVE:0:U, ip4tx:DERIVE:0:U, ip6rx:DERIVE:0:U, ip6tx:DERIVE:0:U
116 ipt_bytes value:DERIVE:0:U
117 ipt_packets value:DERIVE:0:U
120 @@ -1239,6 +1239,12 @@ ipstats_la_SOURCES = src/ipstats.c
121 ipstats_la_LDFLAGS = $(PLUGIN_LDFLAGS)
124 +if BUILD_PLUGIN_IPSTATISTICS
125 +pkglib_LTLIBRARIES += ipstatistics.la
126 +ipstatistics_la_SOURCES = src/ipstatistics.c
127 +ipstatistics_la_LDFLAGS = $(PLUGIN_LDFLAGS)
131 pkglib_LTLIBRARIES += ipvs.la
132 ipvs_la_SOURCES = src/ipvs.c
135 @@ -7091,6 +7091,7 @@ AC_PLUGIN([ipc], [$plugi
136 AC_PLUGIN([ipmi], [$plugin_ipmi], [IPMI sensor statistics])
137 AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters])
138 AC_PLUGIN([ipstats], [$plugin_ipstats], [IP packet statistics])
139 +AC_PLUGIN([ipstatistics], [yes], [IP4 and IP6 statistics])
140 AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics])
141 AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics])
142 AC_PLUGIN([iwinfo], [$with_iwinfo], [Common iwinfo wireless statistics])
143 @@ -7542,6 +7543,7 @@ AC_MSG_RESULT([ ipc . . . . . . . . .
144 AC_MSG_RESULT([ ipmi . . . . . . . . $enable_ipmi])
145 AC_MSG_RESULT([ iptables . . . . . . $enable_iptables])
146 AC_MSG_RESULT([ ipstats . . . . . . . $enable_ipstats])
147 +AC_MSG_RESULT([ ipstatistics . . . . $enable_ipstatistics])
148 AC_MSG_RESULT([ ipvs . . . . . . . . $enable_ipvs])
149 AC_MSG_RESULT([ irq . . . . . . . . . $enable_irq])
150 AC_MSG_RESULT([ iwinfo . . . . . . . $enable_iwinfo])
151 --- a/src/collectd.conf.in
152 +++ b/src/collectd.conf.in
154 #@BUILD_PLUGIN_IPC_TRUE@LoadPlugin ipc
155 #@BUILD_PLUGIN_IPMI_TRUE@LoadPlugin ipmi
156 #@BUILD_PLUGIN_IPSTATS_TRUE@LoadPlugin ipstats
157 +#@BUILD_PLUGIN_IPSTATISTICS_TRUE@LoadPlugin ipstatistics
158 #@BUILD_PLUGIN_IPTABLES_TRUE@LoadPlugin iptables
159 #@BUILD_PLUGIN_IPVS_TRUE@LoadPlugin ipvs
160 #@BUILD_PLUGIN_IRQ_TRUE@LoadPlugin irq