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"
}
[ $debug -eq 1 ] && log DEBUG "${@}"
}
+
# -----------------------------------------------------------------------------
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"
;;
esac
+
+# -----------------------------------------------------------------------------
# default sleep function
+
LOOPSLEEPMS_LASTWORK=0
loopsleepms() {
sleep $1
# 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."
tc_devices=
fix_names=
+# -----------------------------------------------------------------------------
+
setclassname() {
if [ "${tc_show}" = "qdisc" ]
then
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) \
#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.");
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
debug(D_SYSTEM, "System has %d processors.", processors);
return processors;
- #endif /* __APPLE__ */
+ #endif /* __APPLE__, __FreeBSD__ */
}
pid_t pid_max = 32768;
// 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
pid_max = (pid_t) max;
return pid_max;
- #endif /* __APPLE__ */
+ #endif /* __APPLE__, __FreeBSD__ */
}
unsigned int hz;
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;
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);
}
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);
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);
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;
-}
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 */
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);