900-add-iwinfo-plugin.patch (8251B)
1 --- a/configure.ac 2 +++ b/configure.ac 3 @@ -804,6 +804,9 @@ AC_CACHE_CHECK([whether clock_boottime a 4 [c_cv_have_clock_boottime_monotonic="no"])) 5 6 7 +# For the iwinfo plugin 8 +AC_CHECK_LIB(iwinfo, iwinfo_backend, [with_iwinfo="yes"], [with_iwinfo="no (libiwinfo not found)"], []) 9 + 10 # For the turbostat plugin 11 have_asm_msrindex_h="no" 12 AC_CHECK_HEADERS(asm/msr-index.h, [have_asm_msrindex_h="yes"]) 13 @@ -5946,6 +5949,7 @@ plugin_interface="no" 14 plugin_ipmi="no" 15 plugin_ipvs="no" 16 plugin_irq="no" 17 +plugin_iwinfo="no" 18 plugin_load="no" 19 plugin_log_logstash="no" 20 plugin_memory="no" 21 @@ -6416,6 +6420,7 @@ AC_PLUGIN([ipmi], [$plugi 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([load], [$plugin_load], [System load]) 28 AC_PLUGIN([log_logstash], [$plugin_log_logstash], [Logstash json_event compatible logging]) 29 @@ -6797,6 +6802,7 @@ AC_MSG_RESULT([ libyajl . . . . . . . 30 AC_MSG_RESULT([ oracle . . . . . . . $with_oracle]) 31 AC_MSG_RESULT([ protobuf-c . . . . . $have_protoc_c]) 32 AC_MSG_RESULT([ protoc 3 . . . . . . $have_protoc3]) 33 +AC_MSG_RESULT([ iwinfo . . . . . . . $with_iwinfo]) 34 AC_MSG_RESULT() 35 AC_MSG_RESULT([ Features:]) 36 AC_MSG_RESULT([ daemon mode . . . . . $enable_daemon]) 37 @@ -6853,6 +6859,7 @@ AC_MSG_RESULT([ ipmi . . . . . . . . 38 AC_MSG_RESULT([ iptables . . . . . . $enable_iptables]) 39 AC_MSG_RESULT([ ipvs . . . . . . . . $enable_ipvs]) 40 AC_MSG_RESULT([ irq . . . . . . . . . $enable_irq]) 41 +AC_MSG_RESULT([ iwinfo . . . . . . . $enable_iwinfo]) 42 AC_MSG_RESULT([ java . . . . . . . . $enable_java]) 43 AC_MSG_RESULT([ load . . . . . . . . $enable_load]) 44 AC_MSG_RESULT([ logfile . . . . . . . $enable_logfile]) 45 --- a/src/collectd.conf.in 46 +++ b/src/collectd.conf.in 47 @@ -135,6 +135,7 @@ 48 #@BUILD_PLUGIN_IPTABLES_TRUE@LoadPlugin iptables 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_LOAD_TRUE@@BUILD_PLUGIN_LOAD_TRUE@LoadPlugin load 54 #@BUILD_PLUGIN_LPAR_TRUE@LoadPlugin lpar 55 @@ -649,6 +650,12 @@ 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 @@ -3127,6 +3127,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,150 @@ 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", 202 + val / sizeof(struct iwinfo_assoclist_entry)); 203 + } 204 + 205 + iwinfo_finish(); 206 +} 207 + 208 +static int iwinfo_read(void) 209 +{ 210 + char line[1024]; 211 + char ifname[128]; 212 + FILE *f; 213 + 214 + f = fopen(PROCNETDEV, "r"); 215 + if (f == NULL) 216 + { 217 + char err[1024]; 218 + WARNING("iwinfo: Unable to open " PROCNETDEV ": %s", 219 + sstrerror(errno, err, sizeof(err))); 220 + return -1; 221 + } 222 + 223 + while (fgets(line, sizeof(line), f)) 224 + { 225 + if (!strchr(line, ':')) 226 + continue; 227 + 228 + if (!sscanf(line, " %127[^:]", ifname)) 229 + continue; 230 + 231 + if (ignorelist_match(ignorelist, ifname)) 232 + continue; 233 + 234 + if (strstr(ifname, "mon.") || strstr(ifname, ".sta") || 235 + strstr(ifname, "tmp.") || strstr(ifname, "wifi")) 236 + continue; 237 + 238 + iwinfo_process(ifname); 239 + } 240 + 241 + fclose(f); 242 + 243 + return 0; 244 +} 245 + 246 +void module_register(void) 247 +{ 248 + plugin_register_config("iwinfo", iwinfo_config, config_keys, config_keys_num); 249 + plugin_register_read("iwinfo", iwinfo_read); 250 +} 251 --- a/src/Makefile.am 252 +++ b/src/Makefile.am 253 @@ -568,6 +568,13 @@ irq_la_SOURCES = irq.c 254 irq_la_LDFLAGS = $(PLUGIN_LDFLAGS) 255 endif 256 257 +if BUILD_PLUGIN_IWINFO 258 +pkglib_LTLIBRARIES += iwinfo.la 259 +iwinfo_la_SOURCES = iwinfo.c 260 +iwinfo_la_LDFLAGS = -module -avoid-version 261 +iwinfo_la_LIBADD = -liwinfo 262 +endif 263 + 264 if BUILD_PLUGIN_JAVA 265 pkglib_LTLIBRARIES += java.la 266 java_la_SOURCES = java.c 267 --- a/src/types.db 268 +++ b/src/types.db 269 @@ -260,6 +260,7 @@ voltage_threshold value:GAUGE:U:U, 270 vs_memory value:GAUGE:0:9223372036854775807 271 vs_processes value:GAUGE:0:65535 272 vs_threads value:GAUGE:0:65535 273 +stations value:GAUGE:0:256 274 275 # 276 # Legacy types