From 76a87876d610a5e607a26efb903fc800556a2e8a Mon Sep 17 00:00:00 2001 From: trick77 Date: Sun, 7 Jan 2024 10:08:31 +0100 Subject: [PATCH] Add local agent scripts --- agent-local/README.md | 28 ++++++++++++++++++++++++++++ agent-local/dpkg | 22 ++++++++++++++++++++++ agent-local/install.sh | 28 ++++++++++++++++++++++++++++ agent-local/ioping | 34 ++++++++++++++++++++++++++++++++++ agent-local/ioping.conf | 3 +++ agent-local/smarttemp | 30 ++++++++++++++++++++++++++++++ 6 files changed, 145 insertions(+) create mode 100644 agent-local/README.md create mode 100755 agent-local/dpkg create mode 100755 agent-local/install.sh create mode 100755 agent-local/ioping create mode 100644 agent-local/ioping.conf create mode 100755 agent-local/smarttemp diff --git a/agent-local/README.md b/agent-local/README.md new file mode 100644 index 0000000..a0f3d4c --- /dev/null +++ b/agent-local/README.md @@ -0,0 +1,28 @@ +# agent-local + +This repository contains a set of Unix agent scripts designed for monitoring Linux Debian servers with Observium. +The typical location for these scripts on the server to be monitored is `/usr/lib/observium_agent/local`. +Please note that installing the scripts alone isn't sufficient. Refer to [Observium's documentation](https://docs.observium.org/unix_agent/) for +guidance on how to use them. + +## Script installation + +Use the provided `install.sh` to directly install from this repository without cloning it. + +## dpgk + +This local agent script supplies package information to Observium. This information is cached for up to 30 minutes +to enhance the efficiency of the poller. No alterations have been applied. + +## ioping + +The local agent implementation of Observium's `ioping` local agent script was no longer functional as of Debian Bookworm. +This revised implementation addresses the issue and introduces the capability to `ioping` multiple drives simultaneously. +However, it's important to note that ioping remains relatively slow even when executed in parallel. +Customize the `ioping.conf` file based on your requirements. + +## smarttemp + +This local agent script serves as a replacement for `hddtemp` since it has been abandoned and is no longer available as of Debian Bookworm. +It utilizes a combination of smartmontools' `smartctl` and `jq` to determine the temperature of all hard drives and +mimicks the output of the `hddtemp` local agent script. diff --git a/agent-local/dpkg b/agent-local/dpkg new file mode 100755 index 0000000..d1c7b41 --- /dev/null +++ b/agent-local/dpkg @@ -0,0 +1,22 @@ +#!/bin/sh +# Cache the file for 30 minutes +# If you want to override this, put the command in cron. +# We cache because it is a 1sec delay, which is painful for the poller + +dpkg=`which dpkg-query` + +if [ $? -eq 0 ]; then + DATE=$(date +%s) + FILE=/tmp/observium-agent-dpkg + + if [ ! -e $FILE ]; then + $dpkg -W --showformat='${Status} ${Package} ${Version} ${Architecture} ${Installed-Size}\n'|grep " installed "|cut -d\ -f4- > $FILE + fi + FILEMTIME=$(stat -c %Y $FILE) + FILEAGE=$(($DATE-$FILEMTIME)) + if [ $FILEAGE -gt 1800 ]; then + $dpkg -W --showformat='${Status} ${Package} ${Version} ${Architecture} ${Installed-Size}\n'|grep " installed "|cut -d\ -f4- > $FILE + fi + echo "<<>>" + cat $FILE +fi diff --git a/agent-local/install.sh b/agent-local/install.sh new file mode 100755 index 0000000..c783317 --- /dev/null +++ b/agent-local/install.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -eo pipefail + +destination_dir=/usr/lib/observium_agent/local + + copy_and_set_permissions() { + local script_name=$1 + read -p "Install ${script_name} script? (y/n): " copy_script + if [[ $copy_script =~ ^[Yy]$ ]]; then + cp ./${script_name}* "${destination_dir}" && chmod +x "${destination_dir}/${script_name}" + echo "${script_name} script copied and permissions set." + fi + } + +if [ -w "${destination_dir}" ]; then + copy_and_set_permissions "dpkg" + copy_and_set_permissions "ioping" + copy_and_set_permissions "smarttemp" + + echo "Installation complete." + if [ -f "${destination_dir}/ioping.conf" ]; then + echo "Don't forget to edit ${destination_dir}/ioping.conf" + fi +else + echo "Error: local agent scripts directory does not exist at ${destination_dir} or is not writeable" + exit 1 +fi diff --git a/agent-local/ioping b/agent-local/ioping new file mode 100755 index 0000000..f9a31c8 --- /dev/null +++ b/agent-local/ioping @@ -0,0 +1,34 @@ +#!/bin/bash + +if ! command -v ioping &> /dev/null; then + echo "Error: ioping is not installed. Please install it before running this script." + exit 1 +fi + +parallel=0 +if [ -r "${0}.conf" ]; then + first_line=$(head -n 1 "${0}.conf") + if [ "${first_line}" = "parallel=yes" ]; then + parallel=1 + elif [ "${first_line}" != "parallel=no" ]; then + echo "Error: first line in ${0}.conf should be 'parallel=no' or 'parallel=yes'" + exit 1 + fi +else + echo "Configuration file ${0}.conf not found or not readable" + exit 1 +fi + +echo '<<>>' + +while IFS= read -r dev; do + if [ "$parallel" -eq 0 ]; then + echo "$dev $(ioping -q -s 16k -D -c 4 -P 3 $dev)" + else + echo "$dev $(ioping -q -s 16k -D -c 4 -P 3 $dev)" & + fi +done < <(tail -n +2 "${0}.conf") + +if [ "$parallel" -eq 1 ]; then + wait +fi diff --git a/agent-local/ioping.conf b/agent-local/ioping.conf new file mode 100644 index 0000000..3ba4a31 --- /dev/null +++ b/agent-local/ioping.conf @@ -0,0 +1,3 @@ +parallel=yes +/dev/sda +/dev/sdb diff --git a/agent-local/smarttemp b/agent-local/smarttemp new file mode 100755 index 0000000..fbb6c03 --- /dev/null +++ b/agent-local/smarttemp @@ -0,0 +1,30 @@ +#!/bin/bash + +if ! command -v smartctl &> /dev/null || ! command -v jq &> /dev/null; then + echo "Error: smartctl or jq is not installed. Please install them before running this script." + exit 1 +fi + +drives=() + +for drive in /dev/sd[a-z]; do + drives+=("$drive") +done + +echo '<<>>' + +for drive in "${drives[@]}"; do + smartctl_output=$(smartctl -a "${drive}" -j) + + model_name=$(echo "$smartctl_output" | jq -r '.model_name') + temperature=$(echo "$smartctl_output" | jq -r '.temperature.current') + + if [ "$temperature" != "null" ]; then + echo -n "|${drive}" + echo -n "|$model_name" + echo -n "|$temperature" + echo -n "|C|" + fi +done + +echo