]> arthur.barton.de Git - netdata.git/commitdiff
Merge pull request #1417 from l2isbad/openvpn_log_plugin
authorCosta Tsaousis <costa@tsaousis.gr>
Thu, 22 Dec 2016 06:31:30 +0000 (08:31 +0200)
committerGitHub <noreply@github.com>
Thu, 22 Dec 2016 06:31:30 +0000 (08:31 +0200)
Openvpn log plugin

13 files changed:
conf.d/Makefile.am
configure.ac
python.d/Makefile.am
python.d/README.md
python.d/freeradius.chart.py
src/common.c
src/common.h
src/daemon.c
src/freebsd_sysctl.c
src/main.c
src/plugin_freebsd.h
src/rrd.c
src/web_client.c

index bec8face03f6dd0c86a6dfcf8c1cd96960802095..b2b247cd7ee2889968333002dddf1a9fc80c37ed 100644 (file)
@@ -29,6 +29,7 @@ dist_pythonconfig_DATA = \
     python.d/dovecot.conf \
     python.d/example.conf \
     python.d/exim.conf \
+    python.d/freeradius.conf \
     python.d/hddtemp.conf \
     python.d/ipfs.conf \
     python.d/memcached.conf \
index d3a362ebdda3e222b4876f6325091a26accfbb4d..ed8f8212b635a6be0d3e3735eb4e80e152b28af9 100644 (file)
@@ -44,6 +44,9 @@ case "$host_os" in
 freebsd*)
        build_target=freebsd
        ;;
+darwin*)
+       build_target=freebsd
+       ;;
 *)
        ;;
 esac
index e8b7f435065dad6ac597c2bf825ef29161fa31b2..4763f0d66956eb85858bc9354a5b7857b60ddd6b 100644 (file)
@@ -14,6 +14,7 @@ dist_python_SCRIPTS = \
     dovecot.chart.py \
     example.chart.py \
     exim.chart.py \
+    freeradius.chart.py \
     hddtemp.chart.py \
     ipfs.chart.py \
     memcached.chart.py \
index cb06f67fe75266ddbf0ea902e3efeff215129437..7d9a732ad095e7856454762d649d3426782005a3 100644 (file)
@@ -235,6 +235,77 @@ Configuration is not needed.
 
 ---
 
+# freeradius
+
+Uses the `radclient` command to provide freeradius statistics. It is not recommended to run it every second.
+
+It produces:
+
+1. **Authentication counters:**
+ * access-accepts
+ * access-rejects
+ * auth-dropped-requests
+ * auth-duplicate-requests
+ * auth-invalid-requests
+ * auth-malformed-requests
+ * auth-unknown-types
+
+2. **Accounting counters:** [optional]
+ * accounting-requests
+ * accounting-responses
+ * acct-dropped-requests
+ * acct-duplicate-requests
+ * acct-invalid-requests
+ * acct-malformed-requests
+ * acct-unknown-types
+
+3. **Proxy authentication counters:** [optional]
+ * proxy-access-accepts
+ * proxy-access-rejects
+ * proxy-auth-dropped-requests
+ * proxy-auth-duplicate-requests
+ * proxy-auth-invalid-requests
+ * proxy-auth-malformed-requests
+ * proxy-auth-unknown-types
+
+4. **Proxy accounting counters:** [optional]
+ * proxy-accounting-requests
+ * proxy-accounting-responses
+ * proxy-acct-dropped-requests
+ * proxy-acct-duplicate-requests
+ * proxy-acct-invalid-requests
+ * proxy-acct-malformed-requests
+ * proxy-acct-unknown-typesa
+
+
+### configuration
+
+Sample:
+
+```yaml
+local:
+  host       : 'localhost'
+  port       : '18121'
+  secret     : 'adminsecret'
+  acct       : False # Freeradius accounting statistics.
+  proxy_auth : False # Freeradius proxy authentication statistics. 
+  proxy_acct : False # Freeradius proxy accounting statistics.
+```
+
+**Freeradius server configuration:**
+
+The configuration for the status server is automatically created in the sites-available directory.
+By default, server is enabled and can be queried from every client. 
+FreeRADIUS will only respond to status-server messages, if the status-server virtual server has been enabled.
+
+To do this, create a link from the sites-enabled directory to the status file in the sites-available directory:
+ * cd sites-enabled
+ * ln -s ../sites-available/status status
+
+and restart/reload your FREERADIUS server.
+
+---
+
 # hddtemp
  
 Module monitors disk temperatures from one or more hddtemp daemons.
index 829c14cb6a3b45d4c310fa4519045167b68471c2..12fb901d2e3a0e12c187830cef4844c27d2bdf3f 100644 (file)
@@ -62,8 +62,8 @@ class Service(SimpleService):
         self.acct = self.configuration.get('acct', False)
         self.proxy_auth = self.configuration.get('proxy_auth', False)
         self.proxy_acct = self.configuration.get('proxy_acct', False)
-        self.echo = [''.join([directory, 'echo']) for directory in directories if isfile(''.join([directory, 'echo']))][0]
-        self.radclient = [''.join([directory, 'radclient']) for directory in directories if isfile(''.join([directory, 'radclient']))][0]
+        self.echo = [''.join([directory, 'echo']) for directory in directories if isfile(''.join([directory, 'echo']))][:1]
+        self.radclient = [''.join([directory, 'radclient']) for directory in directories if isfile(''.join([directory, 'radclient']))][:1]
         self.sub_echo = [self.echo, 'Message-Authenticator = 0x00, FreeRADIUS-Statistics-Type = 15, Response-Packet-Type = Access-Accept']
         self.sub_radclient = [self.radclient, '-r', '1', '-t', '1', ':'.join([self.host, self.port]), 'status', self.secret]
     
index 78e5896e98babc1ef91f67630256a2128ce7d6d4..36fa0c9be53468ff5cea44affbf86149da8b4422 100644 (file)
@@ -1,9 +1,12 @@
 #include "common.h"
 
-#ifdef __FreeBSD__
+#ifdef __APPLE__
+#define INHERIT_NONE 0
+#endif /* __APPLE__ */
+#if defined(__FreeBSD__) || defined(__APPLE__)
 #    define O_NOATIME     0
 #    define MADV_DONTFORK INHERIT_NONE
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __APPLE__*/
 
 char *global_host_prefix = "";
 int enable_ksm = 1;
@@ -1027,9 +1030,13 @@ int fd_is_valid(int fd) {
 pid_t gettid(void) {
 #ifdef __FreeBSD__
     return (pid_t)pthread_getthreadid_np();
+#elif defined(__APPLE__)
+    uint64_t curthreadid;
+    pthread_threadid_np(NULL, &curthreadid);
+    return (pid_t)curthreadid;
 #else
     return (pid_t)syscall(SYS_gettid);
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__, __APPLE__*/
 }
 
 char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len) {
index ff868b91743eaa70b94a0b4594aac46e28c5ac34..26fd61d68611c5032c233263c09cc6227e585640 100644 (file)
@@ -20,9 +20,9 @@
 
 #else /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
 
-#ifndef __FreeBSD__
+#if !(defined(__FreeBSD__) || defined(__APPLE__))
 #include <malloc.h>
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __APPLE__ */
 
 #endif
 
@@ -64,9 +64,9 @@
 #include <signal.h>
 #include <syslog.h>
 #include <sys/mman.h>
-#ifndef __FreeBSD__
+#if !(defined(__FreeBSD__) || defined(__APPLE__))
 #include <sys/prctl.h>
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __APPLE__*/
 #include <sys/resource.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include "plugin_checks.h"
 #include "plugin_idlejitter.h"
 #include "plugin_nfacct.h"
-#ifndef __FreeBSD__
+#if !(defined(__FreeBSD__) || defined(__APPLE__))
 #include "plugin_proc.h"
 #else
 #include "plugin_freebsd.h"
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __APPLE__*/
 #include "plugin_tc.h"
 #include "plugins_d.h"
 
index c63634f060d5b8b09b76bac6fe698c0fe6acc7c6..4fd8ca5e5984b1e32c14730bb3f7ca3e35644daf 100644 (file)
@@ -117,12 +117,20 @@ int become_user(const char *username, int pid_fd)
         ngroups = 0;
     }
 
+#ifdef __APPLE__
+    if(setregid(gid, gid) != 0) {
+#else
     if(setresgid(gid, gid, gid) != 0) {
+#endif /* __APPLE__ */
         error("Cannot switch to user's %s group (gid: %u).", username, gid);
         return -1;
     }
 
+#ifdef __APPLE__
+    if(setreuid(uid, uid) != 0) {
+#else
     if(setresuid(uid, uid, uid) != 0) {
+#endif /* __APPLE__ */
         error("Cannot switch to user %s (uid: %u).", username, uid);
         return -1;
     }
index da85b838331a862aaca5a4ffbb614d9b796e6940..30768ffa72243f981872bce2711abf7cce29ca07 100644 (file)
@@ -1,5 +1,6 @@
 #include "common.h"
 
+#ifndef __APPLE__
 // NEEDED BY: struct vmtotal, struct vmmeter
 #include <sys/vmmeter.h>
 // NEEDED BY: struct devstat
@@ -18,6 +19,7 @@
 #define _IFI_OQDROPS // It is for FreeNAS only. Most probably in future releases of FreeNAS it will be removed
 #include <net/if.h>
 #include <ifaddrs.h>
+#endif /* __APPLE__ */
 // NEEDED BY: do_disk_io
 #define RRD_TYPE_DISK "disk"
 
@@ -71,6 +73,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
     static usec_t last_loadavg_usec = 0;
     struct loadavg sysload;
 
+#ifndef __APPLE__
     // NEEDED BY: do_cpu, do_cpu_cores
     long cp_time[CPUSTATES];
 
@@ -177,6 +180,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
 
     // --------------------------------------------------------------------
 
+#endif /* __APPLE__ */
     if (last_loadavg_usec <= dt) {
         if (likely(do_loadavg)) {
             if (unlikely(GETSYSCTL("vm.loadavg", sysload))) {
@@ -203,6 +207,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
         last_loadavg_usec = st->update_every * USEC_PER_SEC;
     }
     else last_loadavg_usec -= dt;
+#ifndef __APPLE__
 
     // --------------------------------------------------------------------
 
@@ -1188,6 +1193,7 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
             freeifaddrs(ifap);
         }
     }
+#endif /* __APPLE__ */
 
     return 0;
 }
index b9ab4ef316148e57edb29dfbe514cd6de0e05a7c..ab651a7735169cdd38e0ecd201761909b20348e1 100644 (file)
@@ -45,11 +45,11 @@ struct netdata_static_thread {
 
     {"tc",                 "plugins",   "tc",         1, NULL, NULL, tc_main},
     {"idlejitter",         "plugins",   "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
-#ifndef __FreeBSD__
+#if !(defined(__FreeBSD__) || defined(__APPLE__))
     {"proc",               "plugins",   "proc",       1, NULL, NULL, proc_main},
 #else
     {"freebsd",            "plugins",   "freebsd",    1, NULL, NULL, freebsd_main},
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __APPLE__*/
     {"cgroups",            "plugins",   "cgroups",    1, NULL, NULL, cgroups_main},
     {"check",              "plugins",   "checks",     0, NULL, NULL, checks_main},
     {"backends",            NULL,       NULL,         1, NULL, NULL, backends_main},
@@ -467,9 +467,9 @@ int main(int argc, char **argv)
             if(setrlimit(RLIMIT_CORE, &rl) != 0)
                 error("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
 
-#ifndef __FreeBSD__
+#if !(defined(__FreeBSD__) || defined(__APPLE__))
             prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __APPLE__*/
         }
 
         // --------------------------------------------------------------------
@@ -644,9 +644,9 @@ int main(int argc, char **argv)
         struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
         if(setrlimit(RLIMIT_CORE, &rl) != 0)
             error("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
-#ifndef __FreeBSD__
+#if !(defined(__FreeBSD__) || defined(__APPLE__))
         prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
-#endif /* __FreeBSD__ */
+#endif /* __FreeBSD__ || __APPLE__*/
     }
 #endif /* NETDATA_INTERNAL_CHECKS */
 
index 4ae1a4c21831e7b8ba7f291c6794dbb2190d8d5a..e4767a091310399a39eeade063c6d446e501ad75 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef NETDATA_PLUGIN_FREEBSD_H
 #define NETDATA_PLUGIN_FREEBSD_H 1
 
+#include <sys/sysctl.h>
+
 #define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
 
 void *freebsd_main(void *ptr);
index 72b264affa86ae7195c6c426b1b9653c56ca99d4..0b0da71d04d163a1fcc74868895771adc29ef97c 100644 (file)
--- a/src/rrd.c
+++ b/src/rrd.c
@@ -548,6 +548,11 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
         st->mapped = rrd_memory_mode;
         st->variables = NULL;
         st->alarms = NULL;
+        memset(&st->rwlock, 0, sizeof(pthread_rwlock_t));
+        memset(&st->avl, 0, sizeof(avl));
+        memset(&st->avlname, 0, sizeof(avl));
+        memset(&st->variables_root_index, 0, sizeof(avl_tree_lock));
+        memset(&st->dimensions_index, 0, sizeof(avl_tree_lock));
     }
     else {
         st = callocz(1, size);
@@ -708,6 +713,7 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
         rd->variables = NULL;
         rd->next = NULL;
         rd->name = NULL;
+        memset(&rd->avl, 0, sizeof(avl));
     }
     else {
         // if we didn't manage to get a mmap'd dimension, just create one
index 2d2e84f93c67b80e5063a86e7fa881a6adeb5acf..f6cb4c68d2cccfda3c9e0addaa56246f98bc89c0 100644 (file)
@@ -414,7 +414,11 @@ int mysendfile(struct web_client *w, char *filename)
     w->wait_send = 0;
     buffer_flush(w->response.data);
     w->response.rlen = stat.st_size;
+#ifdef __APPLE__
+    w->response.data->date = stat.st_mtimespec.tv_sec;
+#else
     w->response.data->date = stat.st_mtim.tv_sec;
+#endif /* __APPLE__ */
     buffer_cacheable(w->response.data);
 
     return 200;