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.

276 lines
8.1 KiB

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