]> arthur.barton.de Git - netdata.git/commitdiff
Merge pull request #1687 from l2isbad/use_path_env_var
authorCosta Tsaousis <costa@tsaousis.gr>
Wed, 1 Feb 2017 06:29:15 +0000 (08:29 +0200)
committerGitHub <noreply@github.com>
Wed, 1 Feb 2017 06:29:15 +0000 (08:29 +0200)
new python SimpleService method: use PATH to find binary

plugins.d/tc-qos-helper.sh
src/Makefile.am
src/apps_plugin.c
src/common.c
src/freebsd_sysctl.c
src/plugin_freebsd.c
src/plugin_freebsd.h
src/plugin_macos.c

index 6dd9bfb59b29da4b3e5e70c167547b99d2eed265..074fece9a5e3d571618a69a0c3942ac7b11cd0ea 100755 (executable)
 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
 export LC_ALL=C
 
+
+# -----------------------------------------------------------------------------
+# find /var/run/fireqos
+
+# the default
+fireqos_run_dir="/var/run/fireqos"
+
+function realdir {
+    local r="$1"
+    local t=$(readlink "$r")
+
+    while [ "$t" ]
+        do
+        r=$(cd $(dirname "$r") && cd $(dirname "$t") && pwd -P)/$(basename "$t")
+        t=$(readlink "$r")
+    done
+
+    dirname "$r"
+}
+
+if [ ! -d "${fireqos_run_dir}" ]
+    then
+
+    # the fireqos executable - we will use it to find its config
+    fireqos="$(which fireqos 2>/dev/null || command -v fireqos 2>/dev/null)"
+
+    if [ ! -z "${fireqos}" ]
+        then
+
+        fireqos_exec_dir="$(realdir ${fireqos})"
+
+        if [ ! -z "${fireqos_exec_dir}" -a "${fireqos_exec_dir}" != "." -a -f "${fireqos_exec_dir}/install.config" ]
+            then
+
+            LOCALSTATEDIR=
+            source "${fireqos_exec_dir}/install.config"
+
+            if [ -d "${LOCALSTATEDIR}/run/fireqos" ]
+                then
+                fireqos_run_dir="${LOCALSTATEDIR}/run/fireqos"
+            fi
+        fi
+    fi
+fi
+
+# -----------------------------------------------------------------------------
+# logging functions
+
 PROGRAM_FILE="$0"
 PROGRAM_NAME="$(basename $0)"
 PROGRAM_NAME="${PROGRAM_NAME/.plugin}"
 
-# -----------------------------------------------------------------------------
-
 logdate() {
     date "+%Y-%m-%d %H:%M:%S"
 }
@@ -52,6 +98,7 @@ debug() {
     [ $debug -eq 1 ] && log DEBUG "${@}"
 }
 
+
 # -----------------------------------------------------------------------------
 
 plugins_dir="${NETDATA_PLUGINS_DIR}"
@@ -59,19 +106,33 @@ plugins_dir="${NETDATA_PLUGINS_DIR}"
 
 config_dir=${NETDATA_CONFIG_DIR-/etc/netdata}
 tc="$(which tc 2>/dev/null || command -v tc 2>/dev/null)"
-fireqos_run_dir="/var/run/fireqos"
+
+
+# -----------------------------------------------------------------------------
+# user configuration
+
+# time in seconds to refresh QoS class/qdisc names
 qos_get_class_names_every=120
+
+# time in seconds to exit - netdata will restart the script
 qos_exit_every=3600
 
+# what to use? classes or qdiscs?
 tc_show="qdisc" # can also be "class"
 
+
+# -----------------------------------------------------------------------------
 # check if we have a valid number for interval
+
 t=${1}
 update_every=$((t))
 [ $((update_every)) -lt 1 ] && update_every=${NETDATA_UPDATE_EVERY}
 [ $((update_every)) -lt 1 ] && update_every=1
 
+
+# -----------------------------------------------------------------------------
 # allow the user to override our defaults
+
 if [ -f "${config_dir}/tc-qos-helper.conf" ]
     then
     source "${config_dir}/tc-qos-helper.conf"
@@ -87,7 +148,10 @@ case "${tc_show}" in
         ;;
 esac
 
+
+# -----------------------------------------------------------------------------
 # default sleep function
+
 LOOPSLEEPMS_LASTWORK=0
 loopsleepms() {
     sleep $1
@@ -97,6 +161,10 @@ loopsleepms() {
 # with a high resolution timer function for precise looping.
 . "${plugins_dir}/loopsleepms.sh.inc"
 
+
+# -----------------------------------------------------------------------------
+# final checks we can run
+
 if [ -z "${tc}" -o ! -x "${tc}" ]
     then
     fatal "cannot find command 'tc' in this system."
@@ -105,6 +173,8 @@ fi
 tc_devices=
 fix_names=
 
+# -----------------------------------------------------------------------------
+
 setclassname() {
     if [ "${tc_show}" = "qdisc" ]
         then
index 921b26e5e6e90fd49fac4e9a7f2a0031f48ff947..bec3ef92d80db15b9264ce6481211bbe781de399 100644 (file)
@@ -135,6 +135,12 @@ apps_plugin_SOURCES = \
        web_buffer.c web_buffer.h \
        $(NULL)
 
+if FREEBSD
+apps_plugin_SOURCES += \
+       plugin_freebsd.h \
+       $(NULL)
+endif
+
 apps_plugin_LDADD = \
        $(OPTIONAL_MATH_LIBS) \
        $(OPTIONAL_CAP_LIBS) \
index 67921fb9e9747d4a12523b0450338a7d30da0064..1627a2cee0c7c8067bf596d33c64f2a29b97d5c3 100644 (file)
@@ -3026,20 +3026,6 @@ static int am_i_running_as_root() {
 
 #ifdef HAVE_CAPABILITY
 static int check_capabilities() {
-    if(!CAP_IS_SUPPORTED(CAP_DAC_READ_SEARCH)) {
-        error("This system does not support CAP_DAC_READ_SEARCH capability. Please setuid to root apps.plugin.");
-        return 0;
-    }
-    else if(debug)
-        info("System has CAP_DAC_READ_SEARCH capability.");
-
-    if(!CAP_IS_SUPPORTED(CAP_SYS_PTRACE)) {
-        error("This system does not support CAP_SYS_PTRACE capability. Please setuid to root apps.plugin.");
-        return 0;
-    }
-    else if(debug)
-        info("System has CAP_SYS_PTRACE capability.");
-
     cap_t caps = cap_get_proc();
     if(!caps) {
         error("Cannot get current capabilities.");
index 5b6c52505ea20f8bb7983c2620c98385f7316356..f4dfbb02915c759e7d0a36ae6fa32121ee3397b3 100644 (file)
@@ -1110,6 +1110,16 @@ long get_system_cpus(void) {
             processors = tmp_processors;
         }
 
+        return processors;
+    #elif __FreeBSD__
+        int32_t tmp_processors;
+
+        if (unlikely(GETSYSCTL("hw.ncpu", tmp_processors))) {
+            error("Assuming system has %d processors.", processors);
+        } else {
+            processors = tmp_processors;
+        }
+
         return processors;
     #else
 
@@ -1143,7 +1153,7 @@ long get_system_cpus(void) {
     debug(D_SYSTEM, "System has %d processors.", processors);
     return processors;
 
-    #endif /* __APPLE__ */
+    #endif /* __APPLE__, __FreeBSD__ */
 }
 
 pid_t pid_max = 32768;
@@ -1152,6 +1162,17 @@ pid_t get_system_pid_max(void) {
         // As we currently do not know a solution to query pid_max from the os
         // we use the number defined in bsd/sys/proc_internal.h in XNU sources
         pid_max = 99999;
+        return pid_max;
+    #elif __FreeBSD__
+        int32_t tmp_pid_max;
+
+        if (unlikely(GETSYSCTL("kern.pid_max", tmp_pid_max))) {
+            pid_max = 99999;
+            error("Assuming system's maximum pid is %d.", pid_max);
+        } else {
+            pid_max = tmp_pid_max;
+        }
+
         return pid_max;
     #else
 
@@ -1176,7 +1197,7 @@ pid_t get_system_pid_max(void) {
     pid_max = (pid_t) max;
     return pid_max;
 
-    #endif /* __APPLE__ */
+    #endif /* __APPLE__, __FreeBSD__ */
 }
 
 unsigned int hz;
index dda75dcf30b280015033893ea24f07baece68cc6..7243bf5cb17d4b4879c395e8258c4cd01bfb6942 100644 (file)
@@ -826,7 +826,9 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
         if (unlikely(GETSYSCTL("vm.stats.vm.v_active_count",    vmmeter_data.v_active_count) ||
                      GETSYSCTL("vm.stats.vm.v_inactive_count",  vmmeter_data.v_inactive_count) ||
                      GETSYSCTL("vm.stats.vm.v_wire_count",      vmmeter_data.v_wire_count) ||
+#if __FreeBSD_version < 1200016
                      GETSYSCTL("vm.stats.vm.v_cache_count",     vmmeter_data.v_cache_count) ||
+#endif
                      GETSYSCTL("vfs.bufspace",                  vfs_bufspace_count) ||
                      GETSYSCTL("vm.stats.vm.v_free_count",      vmmeter_data.v_free_count))) {
             do_ram = 0;
@@ -839,7 +841,9 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
                 rrddim_add(st, "active",    NULL, system_pagesize, MEGA_FACTOR, RRDDIM_ABSOLUTE);
                 rrddim_add(st, "inactive",  NULL, system_pagesize, MEGA_FACTOR, RRDDIM_ABSOLUTE);
                 rrddim_add(st, "wired",     NULL, system_pagesize, MEGA_FACTOR, RRDDIM_ABSOLUTE);
+#if __FreeBSD_version < 1200016
                 rrddim_add(st, "cache",     NULL, system_pagesize, MEGA_FACTOR, RRDDIM_ABSOLUTE);
+#endif
                 rrddim_add(st, "buffers",   NULL, 1, MEGA_FACTOR, RRDDIM_ABSOLUTE);
                 rrddim_add(st, "free",      NULL, system_pagesize, MEGA_FACTOR, RRDDIM_ABSOLUTE);
             }
@@ -848,7 +852,9 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
             rrddim_set(st, "active",    vmmeter_data.v_active_count);
             rrddim_set(st, "inactive",  vmmeter_data.v_inactive_count);
             rrddim_set(st, "wired",     vmmeter_data.v_wire_count);
+#if __FreeBSD_version < 1200016
             rrddim_set(st, "cache",     vmmeter_data.v_cache_count);
+#endif
             rrddim_set(st, "buffers",   vfs_bufspace_count);
             rrddim_set(st, "free",      vmmeter_data.v_free_count);
             rrdset_done(st);
index d6deb7090a69c7f2a426a9357d7e3fd8aa272d06..4fef148ab6a86da1e82e81f62600b51e850623a5 100644 (file)
@@ -11,12 +11,6 @@ void *freebsd_main(void *ptr) {
     if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
         error("Cannot set pthread cancel state to ENABLE.");
 
-    // disable (by default) various interface that are not needed
-    /*
-    config_get_boolean("plugin:proc:/proc/net/dev:lo", "enabled", 0);
-    config_get_boolean("plugin:proc:/proc/net/dev:fireqos_monitor", "enabled", 0);
-    */
-
     // when ZERO, attempt to do it
     int vdo_cpu_netdata             = !config_get_boolean("plugin:freebsd", "netdata server resources", 1);
     int vdo_freebsd_sysctl          = !config_get_boolean("plugin:freebsd", "sysctl", 1);
@@ -56,18 +50,3 @@ void *freebsd_main(void *ptr) {
     pthread_exit(NULL);
     return NULL;
 }
-
-int getsysctl(const char *name, void *ptr, size_t len)
-{
-    size_t nlen = len;
-
-    if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
-        error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
-        return 1;
-    }
-    if (unlikely(nlen != len)) {
-        error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
-        return 1;
-    }
-    return 0;
-}
index e4767a091310399a39eeade063c6d446e501ad75..3a1ac39100ff884171bfcb5bdb0a7b3b7afa6e96 100644 (file)
@@ -7,8 +7,21 @@
 
 void *freebsd_main(void *ptr);
 
-int getsysctl(const char *name, void *ptr, size_t len);
-
 extern int do_freebsd_sysctl(int update_every, usec_t dt);
 
+static inline int getsysctl(const char *name, void *ptr, size_t len)
+{
+    size_t nlen = len;
+
+    if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
+        error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
+        return 1;
+    }
+    if (unlikely(nlen != len)) {
+        error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
+        return 1;
+    }
+    return 0;
+}
+
 #endif /* NETDATA_PLUGIN_FREEBSD_H */
index cf4f740266caf443a746648e41064fd3d307f073..54965c5d4ec92813750f0d00265b54e1458268b6 100644 (file)
@@ -11,12 +11,6 @@ void *macos_main(void *ptr) {
     if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
         error("Cannot set pthread cancel state to ENABLE.");
 
-    // disable (by default) various interface that are not needed
-    /*
-    config_get_boolean("plugin:proc:/proc/net/dev:lo", "enabled", 0);
-    config_get_boolean("plugin:proc:/proc/net/dev:fireqos_monitor", "enabled", 0);
-    */
-
     // when ZERO, attempt to do it
     int vdo_cpu_netdata             = !config_get_boolean("plugin:macos", "netdata server resources", 1);
     int vdo_macos_sysctl            = !config_get_boolean("plugin:macos", "sysctl", 1);