You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
8.2 KiB

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