From 4e430cd89653b104a6f25a47c27085fc9c5a014a Mon Sep 17 00:00:00 2001 From: Andrey Abramov Date: Tue, 18 Feb 2020 16:57:39 +0300 Subject: [PATCH 1/3] treshold threshold --- sls/collectd/pkg.sls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sls/collectd/pkg.sls b/sls/collectd/pkg.sls index 27f79b9..f24bde1 100644 --- a/sls/collectd/pkg.sls +++ b/sls/collectd/pkg.sls @@ -5,7 +5,7 @@ include: - gentoo.portage.packages {%- set extra_plugins = salt.pillar.get('collectd:extra-plugins', []) %} -{% set makeconf_collectd_plugins = 'aggregation apcups cgroups chrony contextswitch conntrack cpu cpufreq csv curl curl_json curl_xml dbi df disk entropy ethstat exec filecount fscache interface iptables ipvs irq load logfile memcached memory nfs netlink network nginx numa hugepages processes python sensors swap syslog log_logstash statsd table tail target_notification treshold unixsock uptime users vmem write_graphite write_riemann write_prometheus ' + ' '.join(extra_plugins) %} +{% set makeconf_collectd_plugins = 'aggregation apcups cgroups chrony contextswitch conntrack cpu cpufreq csv curl curl_json curl_xml dbi df disk entropy ethstat exec filecount fscache interface iptables ipvs irq load logfile memcached memory nfs netlink network nginx numa hugepages processes python sensors swap syslog log_logstash statsd table tail target_notification threshold unixsock uptime users vmem write_graphite write_riemann write_prometheus ' + ' '.join(extra_plugins) %} manage-collectd-plugins: augeas.change: From 2492a42a4557c29d37138528bba0fda842f5ad1a Mon Sep 17 00:00:00 2001 From: Andrey Abramov Date: Wed, 19 Feb 2020 15:44:26 +0300 Subject: [PATCH 2/3] add if in case java is absent --- sls/collectd/files/collectd.init | 76 ++++++++++++++++++++++++++++++++ sls/collectd/service.sls | 8 ++++ 2 files changed, 84 insertions(+) create mode 100755 sls/collectd/files/collectd.init diff --git a/sls/collectd/files/collectd.init b/sls/collectd/files/collectd.init new file mode 100755 index 0000000..d0fd508 --- /dev/null +++ b/sls/collectd/files/collectd.init @@ -0,0 +1,76 @@ +#!/sbin/openrc-run +# Copyright 1999-2018 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +COLLECTD_CONFIGFILE=${COLLECTD_CONFIGFILE:-"/etc/collectd.conf"} +COLLECTD_PIDFILE=${COLLECTD_PIDFILE:-"/run/collectd.pid"} +COLLECTD_NICELEVEL=${COLLECTD_NICELEVEL:-5} +COLLECTD_USER=${COLLECTD_USER:-"collectd"} +COLLECTD_GROUP=${COLLECTD_GROUP:-"collectd"} +COLLECTD_SSDARGS=${COLLECTD_SSDARGS:-"--wait 1000"} +COLLECTD_TERMTIMEOUT=${COLLECTD_TERMTIMEOUT:-"TERM/25/KILL/5"} +COLLECTD_OPTS=${COLLECTD_OPTS:-""} + +command="/usr/sbin/collectd" +command_args="${COLLECTD_OPTS} -C \"${COLLECTD_CONFIGFILE}\" -f" +command_background=true +command_user="${COLLECTD_USER}" +# Java path workaround +if command -v java-config-2 >/dev/null 2>&1; then + java_LDPATH_workaround="--env LD_LIBRARY_PATH=\"$(java-config-2 -g LDPATH)\"" +else + java_LDPATH_workaround="" +fi +start_stop_daemon_args="${COLLECTD_SSDARGS} --nice ${COLLECTD_NICELEVEL} ${java_LDPATH_workaround}" +pidfile="${COLLECTD_PIDFILE}" +retry="${COLLECTD_TERMTIMEOUT}" + +extra_commands="configtest" +description_configtest="Run collectd's internal config check." + +required_files="\"${COLLECTD_CONFIGFILE}\"" + +depend() { + use dns +} + +_checkconfig() { + if [ $(sed '/^$\|^#/d' "${COLLECTD_CONFIGFILE}" | grep 'LoadPlugin[[:space:]]\+oracle' | wc -l) -ge 1 ] ; then + if [ -e /etc/env.d/50oracle-instantclient-basic ] ; then + . /etc/env.d/50oracle-instantclient-basic + export ORACLE_HOME + export TNS_ADMIN + else + ewarn "Unable to set Oracle environment, Oracle plugin wont work" + fi + fi + + local test_command="${command} -t -C \"${COLLECTD_CONFIGFILE}\"" + + eval ${test_command} 1>/dev/null 2>&1 + ret=$? + if [ $ret -ne 0 ]; then + eerror "${SVCNAME} has detected an error in your configuration:" + eval ${test_command} + fi + + return $ret +} + +configtest() { + ebegin "Checking ${SVCNAME} configuration" + _checkconfig + eend $? +} + +start_pre() { + if [ "${RC_CMD}" != "restart" ]; then + configtest || return 1 + fi +} + +stop_pre() { + if [ "${RC_CMD}" = "restart" ]; then + configtest || return 1 + fi +} diff --git a/sls/collectd/service.sls b/sls/collectd/service.sls index 5d056b5..908cd7c 100644 --- a/sls/collectd/service.sls +++ b/sls/collectd/service.sls @@ -10,6 +10,14 @@ collectd: - file: /etc/collectd/collectd.conf - file: /etc/collectd/types.db - file: /etc/collectd/conf.d/ + - file: /etc/init.d/collectd + +/etc/init.d/collectd: + file.managed: + - source: salt://collectd/files/collectd.init + - mode: 755 + - user: root + - group: root /etc/conf.d/collectd: file.managed: From 3206443d8f0333bcce03e60f5b91aa6b730c0782 Mon Sep 17 00:00:00 2001 From: Andrey Abramov Date: Wed, 19 Feb 2020 19:57:11 +0300 Subject: [PATCH 3/3] review fixes --- sls/collectd/files/collectd.init | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sls/collectd/files/collectd.init b/sls/collectd/files/collectd.init index d0fd508..8685f37 100755 --- a/sls/collectd/files/collectd.init +++ b/sls/collectd/files/collectd.init @@ -17,11 +17,11 @@ command_background=true command_user="${COLLECTD_USER}" # Java path workaround if command -v java-config-2 >/dev/null 2>&1; then - java_LDPATH_workaround="--env LD_LIBRARY_PATH=\"$(java-config-2 -g LDPATH)\"" + java_LDPATH="--env LD_LIBRARY_PATH=\"$(java-config-2 -g LDPATH)\"" else - java_LDPATH_workaround="" + java_LDPATH="" fi -start_stop_daemon_args="${COLLECTD_SSDARGS} --nice ${COLLECTD_NICELEVEL} ${java_LDPATH_workaround}" +start_stop_daemon_args="${COLLECTD_SSDARGS} --nice ${COLLECTD_NICELEVEL} ${java_LDPATH}" pidfile="${COLLECTD_PIDFILE}" retry="${COLLECTD_TERMTIMEOUT}"