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