Files

67 lines
1.2 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
2026-05-08 21:18:22 +00:00
set -euo pipefail
section() {
printf '\n== %s ==\n' "$1"
}
run_or_warn() {
local description="$1"
shift
if command -v "$1" >/dev/null 2>&1; then
"$@" || printf 'WARNING: %s command failed\n' "$description"
else
printf 'WARNING: %s command not available\n' "$1"
fi
}
top_processes() {
local sort_key="$1"
if command -v ps >/dev/null 2>&1; then
ps -eo pid,ppid,comm,%cpu,%mem --sort="$sort_key" | head -n 11
else
printf 'WARNING: ps command not available\n'
fi
}
section "Host"
hostname
uptime
section "OS"
if [[ -r /etc/os-release ]]; then
. /etc/os-release
printf '%s\n' "${PRETTY_NAME:-Unknown Linux}"
else
printf 'WARNING: /etc/os-release not readable\n'
fi
uname -r
section "CPU Load"
if [[ -r /proc/loadavg ]]; then
awk '{print "1m="$1, "5m="$2, "15m="$3}' /proc/loadavg
else
uptime
fi
section "Memory"
run_or_warn "memory usage" free -h
section "Disk"
run_or_warn "disk usage" df -h -x tmpfs -x devtmpfs
section "Failed systemd Services"
if command -v systemctl >/dev/null 2>&1; then
systemctl --failed --no-pager || true
else
printf 'WARNING: systemctl command not available\n'
fi
section "Top CPU Processes"
top_processes "-%cpu"
section "Top Memory Processes"
top_processes "-%mem"