-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem-health.sh
More file actions
68 lines (55 loc) · 2.11 KB
/
Copy pathsystem-health.sh
File metadata and controls
68 lines (55 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# set -exo pipefail # this can be used if the user want to open in debugger mode with pipefail safe option along with it
echo "============================================"
echo " System Health Report for $HOSTNAME"
echo " Generated on: $(date | awk '{print $1, $2, $3, $4}')"
echo " Generated by: Ankit"
echo "============================================"
# Disk Usage
echo -e "\nDisk Usage:"
printf "%-20s %-10s %-10s %-10s %-6s %-s\n" "Filesystem" "Size" "Used" "Avail" "Use%" "Mounted on"
df -h --output=source,size,used,avail,pcent,target | tail -n +2
# CPU Load
echo -e "\nCPU Load (1/5/15 min average):"
uptime | awk -F'load average:' '{ print " " $2 }'
# Memory Usage
echo -e "\nMemory Usage:"
free -h | awk 'NR==1 || /Mem|Swap/ { printf " %-10s %-10s %-10s %-10s %-10s %-10s\n", $1, $2, $3, $4, $5, $6 }'
# Failed Services
echo -e "\nFailed Systemd Services:"
FAILED=$(systemctl --failed --no-legend)
if [ -z "$FAILED" ]; then
echo " No failed services."
else
echo "$FAILED" | while read -r line; do
echo " $line"
done
fi
# Top 5 Memory-Consuming Processes
echo -e "\nTop 5 Memory Consuming Processes:"
ps -eo user,pid,%cpu,%mem,command --sort=-%mem | head -n 6 | \
awk '{ printf " %-10s %-6s %-6s %-6s %-s\n", $1, $2, $3, $4, substr($0, index($0,$5), 60) }'
# Top 5 CPU-Consuming Processes
echo -e "\nTop 5 CPU Consuming Processes:"
ps -eo user,pid,%cpu,%mem,command --sort=-%cpu | head -n 6 | \
awk '{ printf " %-10s %-6s %-6s %-6s %-s\n", $1, $2, $3, $4, substr($0, index($0,$5), 60) }'
# Uptime
echo -e "\nSystem Uptime:"
echo " $(uptime -p)"
# Package Updates
echo -e "\nAvailable Package Updates:"
if command -v apt &> /dev/null; then
UPDATES=$(apt list --upgradable 2>/dev/null | grep -v "Listing...")
if [ -z "$UPDATES" ]; then
echo " System is up to date."
else
echo "$UPDATES" | awk '{ print " " $0 }'
fi
elif command -v dnf &> /dev/null; then
dnf check-update || echo " System is up to date."
elif command -v yum &> /dev/null; then
yum check-update || echo " System is up to date."
else
echo " Package manager not supported."
fi
echo -e "\nEnd of Report"