projects
/
collectd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
379ce80
)
wireless plugin: Add bitrate metric.
author
Florian Forster
<octo@collectd.org>
Thu, 11 Oct 2018 16:49:50 +0000
(18:49 +0200)
committer
Florian Forster
<octo@collectd.org>
Fri, 12 Oct 2018 06:21:03 +0000
(08:21 +0200)
src/wireless.c
patch
|
blob
|
history
diff --git
a/src/wireless.c
b/src/wireless.c
index
2e597f3
..
4208d36
100644
(file)
--- a/
src/wireless.c
+++ b/
src/wireless.c
@@
-1,6
+1,6
@@
/**
* collectd - src/wireless.c
/**
* collectd - src/wireless.c
- * Copyright (C) 2006
,2007
Florian octo Forster
+ * Copyright (C) 2006
-2018
Florian octo Forster
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@
-29,7
+29,11
@@
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
-#if !KERNEL_LINUX
+#if KERNEL_LINUX
+#include <linux/if.h>
+#include <linux/wireless.h>
+#include <sys/ioctl.h>
+#else
#error "No applicable input method."
#endif
#error "No applicable input method."
#endif
@@
-90,7
+94,14
@@
static int wireless_read(void) {
/* there are a variety of names for the wireless device */
if ((fh = fopen(WIRELESS_PROC_FILE, "r")) == NULL) {
/* there are a variety of names for the wireless device */
if ((fh = fopen(WIRELESS_PROC_FILE, "r")) == NULL) {
- WARNING("wireless: fopen: %s", STRERRNO);
+ ERROR("wireless plugin: fopen: %s", STRERRNO);
+ return -1;
+ }
+
+ int sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock == -1) {
+ ERROR("wireless plugin: socket: %s", STRERRNO);
+ fclose(fh);
return -1;
}
return -1;
}
@@
-142,9
+153,20
@@
static int wireless_read(void) {
wireless_submit(device, "signal_power", power);
wireless_submit(device, "signal_noise", noise);
wireless_submit(device, "signal_power", power);
wireless_submit(device, "signal_noise", noise);
+ struct iwreq req = {
+ .ifr_ifrn.ifrn_name = {0},
+ };
+ sstrncpy(req.ifr_ifrn.ifrn_name, device, sizeof(req.ifr_ifrn.ifrn_name));
+ if (ioctl(sock, SIOCGIWRATE, &req) == -1) {
+ WARNING("wireless plugin: ioctl(SIOCGIWRATE): %s", STRERRNO);
+ } else {
+ wireless_submit(device, "bitrate", (double)req.u.bitrate.value);
+ }
+
devices_found++;
}
devices_found++;
}
+ close(sock);
fclose(fh);
/* If no wireless devices are present return an error, so the plugin
fclose(fh);
/* If no wireless devices are present return an error, so the plugin