ansible-common/roles/tweaks/files/etc/update-motd.d/01-motd
2024-01-06 17:46:48 +01:00

45 lines
1.2 KiB
Bash

#!/bin/bash
source /etc/environment
# Function to get usage and colorize based on the percentage
get_usage_color() {
local usage=$1
if [ $usage -lt 60 ]; then
echo -e "\e[32m${usage}%\e[0m" # Dark Green for < 60%
elif [ $usage -lt 80 ]; then
echo -e "\e[92m${usage}%\e[0m" # Green for >= 60% and < 80%
elif [ $usage -lt 90 ]; then
echo -e "\e[93m${usage}%\e[0m" # Orange for >= 80% and < 90%
else
echo -e "\e[91m${usage}%\e[0m" # Red for >= 90%
fi
}
echo "===================="
# Hostname
echo "Connecting to: $(hostname) ($PROXMOX_ID)"
# CPU Usage
cpu_usage=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}')
cpu_color=$(get_usage_color ${cpu_usage%.*})
echo "CPU Usage: $cpu_color"
# RAM Usage
ram_usage=$(free | grep Mem | awk '{print $3/$2 * 100.0}')
ram_color=$(get_usage_color ${ram_usage%.*})
echo "RAM Usage: $ram_color"
# Disk Usage
disk_usage=$(df -h / | awk 'NR==2 {print $5}' | sed 's/%//g')
disk_color=$(get_usage_color $disk_usage)
echo "Disk Usage: $disk_color"
# Swap Usage
swap_usage=$(free | grep Swap | awk '{print $3/$2 * 100.0}')
swap_color=$(get_usage_color ${swap_usage%.*})
echo "Swap Usage: $swap_color"
echo -e "====================
"