From: Costa Tsaousis Date: Wed, 1 Feb 2017 06:29:15 +0000 (+0200) Subject: Merge pull request #1687 from l2isbad/use_path_env_var X-Git-Tag: ab-debian_0.20170201.01-0ab1~5 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=ab05dd5f3986e7022437a6a48d276ffe90c7bd06;hp=0f6cda50f0344ca8cc955700ee990cd9578bfb62;p=netdata.git Merge pull request #1687 from l2isbad/use_path_env_var new python SimpleService method: use PATH to find binary --- diff --git a/plugins.d/tc-qos-helper.sh b/plugins.d/tc-qos-helper.sh index 6dd9bfb5..074fece9 100755 --- a/plugins.d/tc-qos-helper.sh +++ b/plugins.d/tc-qos-helper.sh @@ -12,12 +12,58 @@ 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 diff --git a/src/Makefile.am b/src/Makefile.am index 921b26e5..bec3ef92 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) \ diff --git a/src/apps_plugin.c b/src/apps_plugin.c index 67921fb9..1627a2ce 100644 --- a/src/apps_plugin.c +++ b/src/apps_plugin.c @@ -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."); diff --git a/src/common.c b/src/common.c index 5b6c5250..f4dfbb02 100644 --- a/src/common.c +++ b/src/common.c @@ -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; diff --git a/src/freebsd_sysctl.c b/src/freebsd_sysctl.c index dda75dcf..7243bf5c 100644 --- a/src/freebsd_sysctl.c +++ b/src/freebsd_sysctl.c @@ -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); diff --git a/src/plugin_freebsd.c b/src/plugin_freebsd.c index d6deb709..4fef148a 100644 --- a/src/plugin_freebsd.c +++ b/src/plugin_freebsd.c @@ -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; -} diff --git a/src/plugin_freebsd.h b/src/plugin_freebsd.h index e4767a09..3a1ac391 100644 --- a/src/plugin_freebsd.h +++ b/src/plugin_freebsd.h @@ -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 */ diff --git a/src/plugin_macos.c b/src/plugin_macos.c index cf4f7402..54965c5d 100644 --- a/src/plugin_macos.c +++ b/src/plugin_macos.c @@ -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);