-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu-monitoring.sh
executable file
·34 lines (33 loc) · 1.67 KB
/
cpu-monitoring.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
#!/bin/bash
#cpuuse=$(top -n 1 | grep %Cpu | awk '{print $2}'|cut -f 1 -d ".")
while true;
do
cpuuse=$(top -n 1 | grep -A 1 %MEM | awk '{print $10}' | tail -n 1|cut -f 1 -d ".")
MESSAGE="/tmp/cpulogs.log"
if [ "$cpuuse" -ge 1 ]; then
echo "" >> $MESSAGE
echo "=========================================================================================================" >> $MESSAGE
echo "" >> $MESSAGE
echo "$(date) : CPU current usage is: $cpuuse%" >> $MESSAGE
echo "---------------------------------------------------------------------------------------------------------" >> $MESSAGE
echo "" >> $MESSAGE
echo "Top 20 Processes using top command" >> $MESSAGE
echo "" >> $MESSAGE
echo "$(top -bn1 | head -20)" >> $MESSAGE
echo "---------------------------------------------------------------------------------------------------------" >> $MESSAGE
echo "" >> $MESSAGE
echo "Top 20 Processes using ps command" >> $MESSAGE
echo "" >> $MESSAGE
echo "$(ps -eo pcpu,pid,user,args | sort -k 1 -r | head -20)" >> $MESSAGE
echo "---------------------------------------------------------------------------------------------------------" >> $MESSAGE
echo "" >> $MESSAGE
echo "Top 20 IO Consume using iotop command" >> $MESSAGE
echo "" >> $MESSAGE
echo "$(sudo iotop -botqqq --iter=3| head -20)" >> $MESSAGE
echo "" >> $MESSAGE
echo "=========================================================================================================" >> $MESSAGE
else
echo "Server CPU usage is in under threshold"
fi
echo "one"
done