From 741d6c2c032b877a619b17faebbcf55c587f65fb Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 26 Dec 2021 15:33:35 +0000 Subject: [PATCH] Finalise initial collectd implementation ...it's still all untested. --- jobs/collectd/collectd.conf | 59 ---------------------------- jobs/collectd/collectd.job | 25 ------------ src/apt-packages.txt | 1 + src/steps-postinstall/20-collectd.sh | 12 +++++- 4 files changed, 11 insertions(+), 86 deletions(-) delete mode 100644 jobs/collectd/collectd.conf delete mode 100755 jobs/collectd/collectd.job diff --git a/jobs/collectd/collectd.conf b/jobs/collectd/collectd.conf deleted file mode 100644 index 9f396ad..0000000 --- a/jobs/collectd/collectd.conf +++ /dev/null @@ -1,59 +0,0 @@ -Interval 300 - -LoadPlugin load -LoadPlugin thermal -LoadPlugin memory -LoadPlugin disk -LoadPlugin swap -LoadPlugin uptime -#LoadPlugin smart - -LoadPlugin df -LoadPlugin irq -LoadPlugin contextswitch -LoadPlugin interface -LoadPlugin ping -#LoadPlugin nginx -#LoadPlugin ntpd - -LoadPlugin exec - -LoadPlugin processes - -LoadPlugin network - - - MountPoint "/" - MountPoint "/boot" - - - - Interface "eth0" - IgnoreSelected false - - - - Host "elessar.mooncarrot.space" - Host "wopplefox.mooncarrot.space" - Host "ubuntu.mirrors.ovh.net" - #Host "s3-eu-west-1.amazonaws.com" - #Host "github.com" - #Host "api.backblazeb2.com" - - -# -# Host "localhost" -# Port "123" -# - - - CollectMemoryMaps false - - - - - SecurityLevel "Encrypt" - Username "cluster" - Password "{{{PASSWORD}}}" - - diff --git a/jobs/collectd/collectd.job b/jobs/collectd/collectd.job deleted file mode 100755 index e7e69a0..0000000 --- a/jobs/collectd/collectd.job +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -if [[ -z "${COLLECTD_PW}" ]]; then - echo "Error: COLLECTD_PW environment variable is not set"; - exit 1; -fi - -RUN "sudo apt-get install -y collectd liboping0"; - -tmpfile_collectd="$(mktemp --tmpdir "collectd-XXXXXXX")"; - -chmod 0600 "${tmpfile_collectd}"; -sed -e "s/{{{PASSWORD}}}/${COLLECTD_PW}/g" <"${JOBFILE_DIR}/collectd.conf" >"${tmpfile_collectd}"; -unset COLLECTD_PW; - -COPY "${tmpfile_collectd}" "/tmp/collectd.conf"; - -rm "${tmpfile_collectd}"; - -RUN "sudo chown root:root /tmp/collectd.conf"; -RUN "sudo chmod 0600 /tmp/collectd.conf"; -RUN "sudo mv /tmp/collectd.conf /etc/collectd/collectd.conf"; - -RUN "sudo systemctl restart collectd.service"; -RUN "sudo systemctl enable collectd.service"; diff --git a/src/apt-packages.txt b/src/apt-packages.txt index 5d291e4..7cb2f39 100644 --- a/src/apt-packages.txt +++ b/src/apt-packages.txt @@ -10,6 +10,7 @@ iotop jpegoptim jq less +liboping0 lnav lsof netcat diff --git a/src/steps-postinstall/20-collectd.sh b/src/steps-postinstall/20-collectd.sh index 9999336..c3bdb49 100755 --- a/src/steps-postinstall/20-collectd.sh +++ b/src/steps-postinstall/20-collectd.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +collectd_conf_target="/etc/collectd/collectd.conf"; + task_begin "Configurating collectd"; subtask_begin "Stopping collectd"; @@ -8,15 +10,21 @@ subtask_end "$?"; if [[ -r "/etc/collectd/collectd.conf" ]]; then subtask_begin "Moving existing config file aside"; - mv "/etc/collectd/collectd.conf" "/etc/collectd/collectd.conf.bak-$(date +%Y-%m-%d)"; + mv "${collectd_conf_target}" "${collectd_conf_target}.bak-$(date +%Y-%m-%d)"; subtask_end "$?"; fi subtask_begin "Installing configuration file"; +touch "${collectd_conf_target}"; +chmod 0600 "${collectd_conf_target}"; #shellcheck disable=SC2154 -cat configs/collectd.conf | awk -v "user=${collectd_username}" -v "pass=${collectd_password}" '{ gsub("|||USERNAME|||", user); gsub("|||PASSWORD|||", pass); print }' >/etc/collectd/collectd.conf; +cat configs/collectd.conf | awk -v "user=${collectd_username}" -v "pass=${collectd_password}" '{ gsub("|||USERNAME|||", user); gsub("|||PASSWORD|||", pass); print }' >"${collectd_conf_target}"; subtask-end "$?"; subtask_begin "Starting collectd & enabling on boot"; systemctl enable --now collectd; subtask_end "$?"; + +subtask_begin "Cleaning up"; +unset collectd_username collectd_password; +subtask_end "$?";