Lightweight shell script to report basic server performance statistics.
- Total CPU usage
- Total memory usage (Used vs Free + percentage)
- Total disk usage (Used vs Free + percentage)
- Top 5 processes by CPU usage
- Top 5 processes by memory usage
The script is Linux-first (reads /proc) but includes fallbacks for macOS (Darwin). It aims to be dependency-light and usable on most servers.
- POSIX-compatible shell (bash recommended)
- Common system utilities:
ps
,df
,awk
,sed
,top
,vm_stat
(macOS),sysctl
(macOS) numfmt
(optional) improves human-readable memory/disk formatting; the script falls back to simple units ifnumfmt
is missing.
- Make the script executable:
chmod +x server-stats.sh
- Run it:
./server-stats.sh
Example output (trimmed):
========== Server Performance Summary (OS: Linux) ==========
Total CPU usage: 7.2%
========== Memory ==========
Total: 15.56 GiB
Used: 3.12 GiB (20.0%)
Free: 12.44 GiB
========== Disk (aggregated/primary) ==========
Total: 250.00 GiB
Used: 30.50 GiB (12%)
Free: 219.50 GiB
========== Top 5 processes by CPU ==========
PID %CPU %MEM USER COMM
... (top 5 rows) ...
- Linux systems: the script reads
/proc/stat
and/proc/meminfo
for accurate CPU and memory metrics. - macOS: the script parses
top
,vm_stat
, andsysctl
. macOStop
output formats can vary across versions and locales — if CPU% appears incorrect on macOS, inspecttop -l 2 -s 0.5 | grep "CPU usage"
to see how your system prints CPU usage. - Containers/minimal images: some minimal containers may lack
ps
,df
, or/proc
entries; the script will printN/A
or fall back to available tools when that happens.
# Build docker image
docker build --debug --no-cache --tag debian-server:latest .
# Run docker container
docker run -it --name debian-server debian-server:latest /bin/bash
# Run script
./server-stats.sh