[packages] collectd: add iwinfo plugin, similar to wireless but compatible to madwifi...
[openwrt/svn-archive/archive.git] / utils / collectd / patches / 900-add-iwinfo-plugin.patch
1 --- a/configure.in
2 +++ b/configure.in
3 @@ -471,6 +471,9 @@ AC_CHECK_HEADERS(netinet/if_ether.h, [],
4 have_termios_h="no"
5 AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
6
7 +# For the iwinfo plugin
8 +AC_CHECK_LIB(iwinfo, iwinfo_backend, [with_iwinfo="yes"], [with_iwinfo="no (libiwinfo not found)"], [])
9 +
10 #
11 # Checks for typedefs, structures, and compiler characteristics.
12 #
13 @@ -3985,6 +3988,7 @@ plugin_interface="no"
14 plugin_ipmi="no"
15 plugin_ipvs="no"
16 plugin_irq="no"
17 +plugin_iwinfo="no"
18 plugin_libvirt="no"
19 plugin_load="no"
20 plugin_memory="no"
21 @@ -4292,6 +4296,7 @@ AC_PLUGIN([ipmi], [$plugin_ipmi],
22 AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters])
23 AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics])
24 AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics])
25 +AC_PLUGIN([iwinfo], [$with_iwinfo], [Common iwinfo wireless statistics])
26 AC_PLUGIN([java], [$with_java], [Embed the Java Virtual Machine])
27 AC_PLUGIN([libvirt], [$plugin_libvirt], [Virtual machine statistics])
28 AC_PLUGIN([load], [$plugin_load], [System load])
29 @@ -4570,6 +4575,7 @@ Configuration:
30 protobuf-c . . . . . $have_protoc_c
31 oracle . . . . . . . $with_oracle
32 python . . . . . . . $with_python
33 + iwinfo . . . . . . . $with_iwinfo
34
35 Features:
36 daemon mode . . . . . $enable_daemon
37 @@ -4609,6 +4615,7 @@ Configuration:
38 iptables . . . . . . $enable_iptables
39 ipvs . . . . . . . . $enable_ipvs
40 irq . . . . . . . . . $enable_irq
41 + iwinfo . . . . . . . $enable_iwinfo
42 java . . . . . . . . $enable_java
43 libvirt . . . . . . . $enable_libvirt
44 load . . . . . . . . $enable_load
45 --- a/src/collectd.conf.in
46 +++ b/src/collectd.conf.in
47 @@ -82,6 +82,7 @@ FQDNLookup true
48 #@BUILD_PLUGIN_IPMI_TRUE@LoadPlugin ipmi
49 #@BUILD_PLUGIN_IPVS_TRUE@LoadPlugin ipvs
50 #@BUILD_PLUGIN_IRQ_TRUE@LoadPlugin irq
51 +#@BUILD_PLUGIN_IWINFO_TRUE@LoadPlugin iwinfo
52 #@BUILD_PLUGIN_JAVA_TRUE@LoadPlugin java
53 #@BUILD_PLUGIN_LIBVIRT_TRUE@LoadPlugin libvirt
54 @BUILD_PLUGIN_LOAD_TRUE@@BUILD_PLUGIN_LOAD_TRUE@LoadPlugin load
55 @@ -372,6 +373,12 @@ FQDNLookup true
56 # IgnoreSelected true
57 #</Plugin>
58
59 +#<Plugin iwinfo>
60 +# Interface "ath0"
61 +# Interface "ra0"
62 +# Interface "wlan0"
63 +#</Plugin>
64 +
65 #<Plugin "java">
66 # JVMArg "-verbose:jni"
67 # JVMArg "-Djava.class.path=@prefix@/share/collectd/java/collectd-api.jar"
68 --- a/src/collectd.conf.pod
69 +++ b/src/collectd.conf.pod
70 @@ -1468,6 +1468,27 @@ and all other interrupts are collected.
71
72 =back
73
74 +=head2 Plugin C<iwinfo>
75 +
76 +=over 4
77 +
78 +=item B<Interface> I<Interface>
79 +
80 +Select this interface. By default all detected wireless interfaces will be
81 +collected. For a more detailed description see B<IgnoreSelected> below.
82 +
83 +=item B<IgnoreSelected> I<true>|I<false>
84 +
85 +If no configuration if given, the B<iwinfo>-plugin will collect data from all
86 +detected wireless interfaces. You can use the B<Interface>-option to pick the
87 +interfaces you're interested in. Sometimes, however, it's easier/preferred to
88 +collect all interfaces I<except> a few ones. This option enables you to do
89 +that: By setting B<IgnoreSelected> to I<true> the effect of B<Interface> is
90 +inverted: All selected interfaces are ignored and all other interfaces are
91 +collected.
92 +
93 +=back
94 +
95 =head2 Plugin C<java>
96
97 The I<Java> plugin makes it possible to write extensions for collectd in Java.
98 --- /dev/null
99 +++ b/src/iwinfo.c
100 @@ -0,0 +1,149 @@
101 +/**
102 + * collectd - src/iwinfo.c
103 + * Copyright (C) 2011 Jo-Philipp Wich
104 + *
105 + * This program is free software; you can redistribute it and/or modify it
106 + * under the terms of the GNU General Public License as published by the
107 + * Free Software Foundation; only version 2 of the License is applicable.
108 + *
109 + * This program is distributed in the hope that it will be useful, but
110 + * WITHOUT ANY WARRANTY; without even the implied warranty of
111 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
112 + * General Public License for more details.
113 + *
114 + * You should have received a copy of the GNU General Public License along
115 + * with this program; if not, write to the Free Software Foundation, Inc.,
116 + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
117 + **/
118 +
119 +#include "collectd.h"
120 +#include "common.h"
121 +#include "plugin.h"
122 +#include "utils_ignorelist.h"
123 +
124 +#include <stdint.h>
125 +#include <iwinfo.h>
126 +
127 +#define PROCNETDEV "/proc/net/dev"
128 +
129 +static const char *config_keys[] = {
130 + "Interface",
131 + "IgnoreSelected"
132 +};
133 +static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
134 +
135 +static ignorelist_t *ignorelist = NULL;
136 +
137 +static int iwinfo_config(const char *key, const char *value)
138 +{
139 + if (ignorelist == NULL)
140 + ignorelist = ignorelist_create(1);
141 +
142 + if (ignorelist == NULL)
143 + return 1;
144 +
145 + if (strcasecmp(key, "Interface") == 0)
146 + ignorelist_add(ignorelist, value);
147 + else if (strcasecmp(key, "IgnoreSelected") == 0)
148 + ignorelist_set_invert(ignorelist, IS_TRUE(value) ? 0 : 1);
149 + else
150 + return -1;
151 +
152 + return 0;
153 +}
154 +
155 +static void iwinfo_submit(const char *ifname, const char *type, int value)
156 +{
157 + value_t values[1];
158 + value_list_t vl = VALUE_LIST_INIT;
159 +
160 + values[0].gauge = value;
161 +
162 + vl.values = values;
163 + vl.values_len = 1;
164 +
165 + sstrncpy(vl.host, hostname_g, sizeof(vl.host));
166 + sstrncpy(vl.plugin, "iwinfo", sizeof(vl.plugin));
167 + sstrncpy(vl.plugin_instance, ifname, sizeof(vl.plugin_instance));
168 + sstrncpy(vl.type, type, sizeof(vl.type));
169 + /*sstrncpy(vl.type_instance, "", sizeof(vl.type_instance));*/
170 +
171 + plugin_dispatch_values(&vl);
172 +}
173 +
174 +static void iwinfo_process(const char *ifname)
175 +{
176 + int val;
177 + char buf[IWINFO_BUFSIZE];
178 + const struct iwinfo_ops *iw = iwinfo_backend(ifname);
179 +
180 + /* does appear to be a wifi iface */
181 + if (iw)
182 + {
183 + if (iw->bitrate(ifname, &val))
184 + val = 0;
185 + iwinfo_submit(ifname, "bitrate", val * 1000);
186 +
187 + if (iw->signal(ifname, &val))
188 + val = 0;
189 + iwinfo_submit(ifname, "signal_power", val);
190 +
191 + if (iw->noise(ifname, &val))
192 + val = 0;
193 + iwinfo_submit(ifname, "signal_noise", val);
194 +
195 + if (iw->quality(ifname, &val))
196 + val = 0;
197 + iwinfo_submit(ifname, "signal_quality", val);
198 +
199 + if (iw->assoclist(ifname, buf, &val))
200 + val = 0;
201 + iwinfo_submit(ifname, "stations", val);
202 + }
203 +
204 + iwinfo_finish();
205 +}
206 +
207 +static int iwinfo_read(void)
208 +{
209 + char line[1024];
210 + char ifname[128];
211 + FILE *f;
212 +
213 + f = fopen(PROCNETDEV, "r");
214 + if (f == NULL)
215 + {
216 + char err[1024];
217 + WARNING("iwinfo: Unable to open " PROCNETDEV ": %s",
218 + sstrerror(errno, err, sizeof(err)));
219 + return -1;
220 + }
221 +
222 + while (fgets(line, sizeof(line), f))
223 + {
224 + if (!strchr(line, ':'))
225 + continue;
226 +
227 + if (!sscanf(line, " %127[^:]", ifname))
228 + continue;
229 +
230 + if (ignorelist_match(ignorelist, ifname))
231 + continue;
232 +
233 + if (strstr(ifname, "mon.") || strstr(ifname, ".sta") ||
234 + strstr(ifname, "wmaster") || strstr(ifname, "wifi"))
235 + continue;
236 +
237 + iwinfo_process(ifname);
238 + }
239 +
240 + fclose(f);
241 +
242 + return 0;
243 +}
244 +
245 +void module_register(void)
246 +{
247 + plugin_register_config("iwinfo", iwinfo_config, config_keys, config_keys_num);
248 + plugin_register_read("iwinfo", iwinfo_read);
249 +}
250 --- a/src/Makefile.am
251 +++ b/src/Makefile.am
252 @@ -452,6 +452,15 @@ collectd_LDADD += "-dlopen" irq.la
253 collectd_DEPENDENCIES += irq.la
254 endif
255
256 +if BUILD_PLUGIN_IWINFO
257 +pkglib_LTLIBRARIES += iwinfo.la
258 +iwinfo_la_SOURCES = iwinfo.c
259 +iwinfo_la_LDFLAGS = -module -avoid-version
260 +iwinfo_la_LIBADD = -liwinfo
261 +collectd_LDADD += "-dlopen" iwinfo.la
262 +collectd_DEPENDENCIES += iwinfo.la
263 +endif
264 +
265 if BUILD_PLUGIN_JAVA
266 pkglib_LTLIBRARIES += java.la
267 java_la_SOURCES = java.c
268 --- a/src/types.db
269 +++ b/src/types.db
270 @@ -171,3 +171,4 @@ voltage value:GAUGE:U:U
271 vs_memory value:GAUGE:0:9223372036854775807
272 vs_processes value:GAUGE:0:65535
273 vs_threads value:GAUGE:0:65535
274 +stations value:GAUGE:0:256