CSchantz Wiki

Quick Commands

Overall Tips

Loadwatch is a good utility that can be installed to monitor issues

/root/loadwatch/

Cert checker

https://www.sslshopper.com/ssl-checker.html

Check Disk Usage

Check for overall drive usage

df -h

Sort folder disk usage from top down

du -hx --max-depth 1 |sort -h -r|head -15

Check memory

Check memory usage

ps aux --sort=-%mem | awk 'NR<=10{print $0}'

or

ps -yale --sort=rss | awk '{print $NF" "$8/1024}' | awk '{ seen[$1] += $2 } END { for (i in seen) print i, seen[i] " MiB" }' | sort -k2 -rn |head

Check total memory on server

grep MemTotal /proc/meminfo

Check free memory

free -m

Sort Top by memory usage

Shift + m

Check memory usage history

sar -r

File Sort Commands

cat load.txt | awk '{print $12}' | sort | uniq -c | sort -rn | head

specific to access logs

cat load.txt | awk '{print $1}' | sort | uniq -c | sort -rn | head

Network

Sort network traffic 

netstat -nao | egrep ":80|:443" | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head
watch "netstat -nao | egrep ':80|:443' | awk '{print \$5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head"

syn attack

netstat -tan | grep SYN_RECV | wc -l

Quick info view

echo "=== System Resources ===" && \
CORES=$(nproc) && \
LOAD=$(uptime | awk -F'load average:' '{print $2}' | awk '{print $1}' | sed 's/,//') && \
CPU_LINE=$(top -bn1 | grep "Cpu(s)") && \
CPU_IDLE=$(echo $CPU_LINE | awk '{print $8}' | sed 's/%id,//') && \
CPU_IOWAIT=$(echo $CPU_LINE | awk '{print $10}' | sed 's/%wa,//') && \
CPU_USED=$(awk "BEGIN {printf \"%.1f\", 100-$CPU_IDLE}") && \
echo "CPU Cores: $CORES" && \
echo "CPU Usage: ${CPU_USED}% (actual)" && \
echo "I/O Wait: ${CPU_IOWAIT}%" && \
echo "Load Average: $LOAD ($(awk "BEGIN {printf \"%.0f\", ($LOAD/$CORES)*100}")% of core capacity)" && \
echo "RAM Total: $(free -h | awk '/^Mem:/ {print $2}')" && \
echo "RAM Used: $(free -h | awk '/^Mem:/ {print $3}' | xargs) ($(free | awk '/^Mem:/ {printf "%.0f%%", $3/$2*100}'))" && \
echo "Uptime: $(uptime -p)"
nprocs=$(nproc) && load=$(uptime | grep -oP 'load average: \K[^,]+') && echo "Cores: $nprocs | 1min Load: $load | Status: $(awk -v l=$load -v c=$nprocs 'BEGIN {if(l > c) print "HIGH"; else if(l > c*0.75) print "MODERATE";
else print "OK"}')"