#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: http://mirrors.slickstack.io/bash/ss-monitor.txt ###################################### #### path: /var/www/ss-monitor ##################################################################### #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Monitors localhost RAM memory usage, disk space, and CPU load in real time ########### #### module version: Ubuntu 20.04 LTS ############################################################## #### sourced by: n/a ############################################################################### #### bash aliases: ss monitor, ss monitor resources, ss resources ################################## #################################################################################################### ## include SlickStack configuration ## source /var/www/ss-config ## include SlickStack functions ## source /var/www/ss-functions #################################################################################################### #### SS-Monitor: Message (Begin Script) ############################################################ #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be noticed by sudo users who manually call ss core bash scripts ## ## echo message ## echo -e "${PURPLE}Running ss-monitor: Monitors localhost RAM memory usage, disk space, and CPU load in real time... ${NOCOLOR}" sleep "$SLEEP_MESSAGE_BEGIN" #################################################################################################### #### SS-Monitor: Output Current Status Of RAM, CPU, Disk Space ##################################### #################################################################################################### printf "Memory\t\tDisk\t\tCPU\n" end=$((SECONDS+3600)) while [ $SECONDS -lt $end ]; do MEMORY=$(free -m | awk 'NR==2{printf "%.2f%%\t\t", $3*100/$2 }') DISK=$(df -h | awk '$NF=="/"{printf "%s\t\t", $5}') CPU=$(top -bn1 | grep load | awk '{printf "%.2f%%\t\t\n", $(NF-2)}') echo "$MEMORY$DISK$CPU" sleep 5 done #################################################################################################### #### SS-Monitor: Touch Timestamp File (End Script) ################################################# #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ## script timestamp ## touch /var/www/meta/.timestamp-ss-monitor #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: http://www.systeen.com/2016/05/07/bash-script-monitor-cpu-memory-disk-usage-linux/ ## Ref: https://archive.is/GM8yS ## Ref: https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load ## Ref: https://www.inmotionhosting.com/support/website/server-usage/create-server-load-monitoring-bash-script/ ## Ref: https://www.tecmint.com/linux-server-health-monitoring-script/ ## Ref: https://www.2daygeek.com/linux-shell-script-to-monitor-cpu-memory-swap-usage-send-email/ ## Ref: https://www.instructables.com/id/Service-Monitor-Script-for-Linux-Servers/ ## Ref: https://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ ## SS_EOF