-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_monitor.sh
69 lines (39 loc) · 1.78 KB
/
system_monitor.sh
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
65
66
67
68
69
#!/bin/bash
#Removing the file if its already exist
if [[ -e /opt/system_monitor.txt ]]; then
sudo rm -f /opt/system_monitor.txt
fi
#Defining the table
sudo echo "No. Name Usage Threshold Warning Hostname" > /opt/system_monitor.txt
#CPU usgae
#calc the cpu idle
cpu_idle=$(top -b -n 1 | grep Cpu | awk '{print $8}' | cut -d '.' -f 1)
cpu_usage=`expr 100 - $cpu_idle`
cpu_threshold=80
if [[ $cpu_usage -gt $cpu_threshold ]]; then
sudo echo "1 Cpu_usage $cpu_usage% $cpu_threshold% YES $(hostname)" >> /opt/system_monitor.txt
else
sudo echo "1 Cpu_usage $cpu_usage% $cpu_threshold% NO $(hostname)" >> /opt/system_monitor.txt
fi
#Ram Memory
ram_threshold=80
ram_usage=$(free -h | grep Mem | awk '{print $3/$2*100}'|xargs printf "%0.f") #RamUsage
if [[ $ram_usage -gt $ram_threshold ]]; then
sudo echo "2 Ram_Usage $ram_usage% $ram_threshold% YES $(hostname)" >> /opt/system_monitor.txt
else
sudo echo "2 Ram_Usage $ram_usage% $ram_threshold% NO $(hostname)" >> /opt/system_monitor.txt
fi
#Disk
disk_threshold=80
disk_usage=$(df . -h |egrep -v 'tmp'| awk '{print $1,$2,$3,$4}'| grep /dev | awk '{print $3/$2*100}' | xargs printf "%0.f")
if [[ $disk_usage -gt $disk_threshold ]]; then
sudo echo "3 Disk_Usage $disk_usage% $disk_threshold% YES $(hostname)" >> /opt/system_monitor.txt
else
sudo echo "3 Disk_Usage $disk_usage% $disk_threshold% NO $(hostname)" >> /opt/system_monitor.txt
fi
#Display output in table format
echo " "
echo "--------------------------------------------------------------"
sudo column -t /opt/system_monitor.txt
echo "--------------------------------------------------------------"
echo " "