From 52764e5bedebfec4caed82df1d6cefbcaab11399 Mon Sep 17 00:00:00 2001 From: samuel-p Date: Sun, 16 May 2021 00:27:56 +0200 Subject: [PATCH] updated node_exporter scripts --- README.md | 28 ++++++++++++++++++++++++++-- login-notify.sh | 4 ++-- node_dir_size_exporter.sh | 8 -------- node_exporter/active-sessions.sh | 9 +++++++++ node_exporter/directory-size.sh | 5 +++++ 5 files changed, 42 insertions(+), 12 deletions(-) delete mode 100644 node_dir_size_exporter.sh create mode 100644 node_exporter/active-sessions.sh create mode 100644 node_exporter/directory-size.sh diff --git a/README.md b/README.md index 885b154..7ec2b49 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,24 @@ Some useful bash scripts. |[validate-remote-backup.sh](validate-remote-backup.sh)|Script to validate server side rsync command to use ssh force command| |[docker-compose-up-all.sh](docker-compose-up-all.sh)|Script to call `docker-compose up -d` on all subdirectories| |[docker-stack-deploy-all.sh](docker-stack-deploy-all.sh)|Script to call `docker stack deploy` on all subdirectories| -|[node_dir_size_exporter.sh](node_dir_size_exporter.sh)|Script to call `du` on a given directory to export the size to prometheus| +|[node_dir_size_exporter.sh](node_exporter/directory-size.sh)|Script to call `du` on a given directory to export the size to prometheus| |[update-notify.sh](update-notify.sh)|Script to call `apt` to check the host for new updates and notify in gotify| +__node_exporter__ + +|Script|Description| +|---|---| +|[active-sessions.sh](node_exporter/active-sessions.sh)|Script to export all active sessions to prometheus| +|[directory-size.sh](node_exporter/directory-size.sh)|Script to export directory sizes to prometheus| + + ## Setup To set up all scripts in the current directory run this: ``` -curl https://git.sp-codes.de/samuel-p/awesome-scripts/raw/branch/master/setup.sh | bash -s healthcheck.sh login-notify.sh validate-remote-backup.sh docker-compose-up-all.sh docker-stack-deploy-all.sh node_dir_size_exporter.sh update-notify.sh +curl https://git.sp-codes.de/samuel-p/awesome-scripts/raw/branch/master/setup.sh | bash -s healthcheck.sh login-notify.sh validate-remote-backup.sh docker-compose-up-all.sh docker-stack-deploy-all.sh update-notify.sh +curl https://git.sp-codes.de/samuel-p/awesome-scripts/raw/branch/master/setup.sh | bash -s active-sessions.sh directory-size.sh ``` ## Usage @@ -41,3 +50,18 @@ Place a `.gotify` file in the same direction as the script and put the applicati ``` session optional pam_exec.so seteuid /path/to/login-notify.sh ``` + +### node_exporter + +Add the following in crontab: + +``` +*/5 * * * * /root/exporter/directory-size.sh "" "" | sponge /path/to/textfiles/directory-size.prom +* * * * * /root/exporter/active-sessions.sh | sponge /path/to/textfiles/active-sessions.prom +``` + +Add the `textfiles` dir as param to `node_exporter`: + +``` +node_exporter --collector.textfile.directory /path/to/textfiles ... +``` diff --git a/login-notify.sh b/login-notify.sh index 2c26a81..cbd2727 100644 --- a/login-notify.sh +++ b/login-notify.sh @@ -3,8 +3,8 @@ GOTIFY_FILE=$(<~/.gotify) GOTIFY_TOKEN=${GOTIFY_FILE##*( )} HOST="$(hostname)" -sender="SSH-Notification " -recipient="codes@samuel-philipp.de" +sender="SSH-Notification " +recipient="" subject="SSH Login: $PAM_USER from $PAM_RHOST on $HOST" message="User $PAM_USER logged in on $HOST from $PAM_RHOST at $(date)." diff --git a/node_dir_size_exporter.sh b/node_dir_size_exporter.sh deleted file mode 100644 index 7ee98e5..0000000 --- a/node_dir_size_exporter.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -DIR=$1 -KEY=$2 -FILE=$3 - -du -bsx $DIR | sed "s/\([0-9]*\).*\/\(.*\)/node_dir_size{name=\"\2\",key=\"$KEY\"} \1/" > "$FILE$$" -mv "$FILE$$" "$FILE" diff --git a/node_exporter/active-sessions.sh b/node_exporter/active-sessions.sh new file mode 100644 index 0000000..d5f68c6 --- /dev/null +++ b/node_exporter/active-sessions.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +ALL_SESSIONS=$(who | wc -l) +ROOT_SESSIONS=$(who | grep root | wc -l) + +echo "# HELP node_active_sessions active sessions by type." +echo "# TYPE node_active_sessions gauge" +echo "node_active_sessions{type=\"all\"} $ALL_SESSIONS" +echo "node_active_sessions{type=\"root\"} $ROOT_SESSIONS" diff --git a/node_exporter/directory-size.sh b/node_exporter/directory-size.sh new file mode 100644 index 0000000..21da1ad --- /dev/null +++ b/node_exporter/directory-size.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "# HELP node_directory_size_bytes Disk space used by some directories" +echo "# TYPE node_directory_size_bytes gauge" +du -bsx "$1" | sed "s/\([0-9]*\).*\/\(.*\)/node_directory_size_bytes{name=\"\2\",key=\"$2\"} \1/"