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
7.7 KiB

  1. --- a/configure.ac
  2. +++ b/configure.ac
  3. @@ -568,6 +568,9 @@ AC_CHECK_HEADERS(net/pfvar.h,
  4. have_termios_h="no"
  5. AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
  6. +# For the iwinfo plugin
  7. +AC_CHECK_LIB(iwinfo, iwinfo_backend, [with_iwinfo="yes"], [with_iwinfo="no (libiwinfo not found)"], [])
  8. +
  9. #
  10. # Checks for typedefs, structures, and compiler characteristics.
  11. #
  12. @@ -4819,6 +4822,7 @@ plugin_interface="no"
  13. plugin_ipmi="no"
  14. plugin_ipvs="no"
  15. plugin_irq="no"
  16. +plugin_iwinfo="no"
  17. plugin_libvirt="no"
  18. plugin_load="no"
  19. plugin_memory="no"
  20. @@ -5157,6 +5161,7 @@ AC_PLUGIN([ipmi], [$plugin_ipmi],
  21. AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters])
  22. AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics])
  23. AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics])
  24. +AC_PLUGIN([iwinfo], [$with_iwinfo], [Common iwinfo wireless statistics])
  25. AC_PLUGIN([java], [$with_java], [Embed the Java Virtual Machine])
  26. AC_PLUGIN([libvirt], [$plugin_libvirt], [Virtual machine statistics])
  27. AC_PLUGIN([load], [$plugin_load], [System load])
  28. @@ -5458,6 +5463,7 @@ Configuration:
  29. protobuf-c . . . . . $have_protoc_c
  30. oracle . . . . . . . $with_oracle
  31. python . . . . . . . $with_python
  32. + iwinfo . . . . . . . $with_iwinfo
  33. Features:
  34. daemon mode . . . . . $enable_daemon
  35. @@ -5502,6 +5508,7 @@ Configuration:
  36. iptables . . . . . . $enable_iptables
  37. ipvs . . . . . . . . $enable_ipvs
  38. irq . . . . . . . . . $enable_irq
  39. + iwinfo . . . . . . . $enable_iwinfo
  40. java . . . . . . . . $enable_java
  41. libvirt . . . . . . . $enable_libvirt
  42. load . . . . . . . . $enable_load
  43. --- a/src/collectd.conf.in
  44. +++ b/src/collectd.conf.in
  45. @@ -109,6 +109,7 @@
  46. #@BUILD_PLUGIN_IPMI_TRUE@LoadPlugin ipmi
  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_LIBVIRT_TRUE@LoadPlugin libvirt
  52. @BUILD_PLUGIN_LOAD_TRUE@@BUILD_PLUGIN_LOAD_TRUE@LoadPlugin load
  53. @@ -467,6 +468,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. @@ -2056,6 +2056,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. @@ -530,6 +530,15 @@ collectd_LDADD += "-dlopen" irq.la
  248. collectd_DEPENDENCIES += irq.la
  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. +collectd_LDADD += "-dlopen" iwinfo.la
  256. +collectd_DEPENDENCIES += iwinfo.la
  257. +endif
  258. +
  259. if BUILD_PLUGIN_JAVA
  260. pkglib_LTLIBRARIES += java.la
  261. java_la_SOURCES = java.c
  262. --- a/src/types.db
  263. +++ b/src/types.db
  264. @@ -195,7 +195,7 @@ voltage value:GAUGE:U:U
  265. vs_memory value:GAUGE:0:9223372036854775807
  266. vs_processes value:GAUGE:0:65535
  267. vs_threads value:GAUGE:0:65535
  268. -
  269. +stations value:GAUGE:0:256
  270. #
  271. # Legacy types
  272. # (required for the v5 upgrade target)