-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcpu_host_process
executable file
·50 lines (40 loc) · 1.35 KB
/
cpu_host_process
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
#!/bin/bash
p="U_server_5"
file="vbox.txt"
uptime=$(cat /proc/uptime | awk '{print $1}')
uptime=${uptime%.*}
pid=$(pgrep -f $p)
ticks=$(getconf CLK_TCK)
u=$(cat /proc/$pid/stat | awk '{print $14}')
s=$(cat /proc/$pid/stat | awk '{print $15}')
cu=$(cat /proc/$pid/stat | awk '{print $16}')
cs=$(cat /proc/$pid/stat | awk '{print $17}')
starttime=$(cat /proc/$pid/stat | awk '{print $22}')
totaltime=$(($u+$s+$cu+$cs))
st=$((starttime/ticks))
seconds=$(($uptime - $st))
tt=$((totaltime/ticks))
tts=$(echo "scale=4; (($tt/$seconds))" | bc -l | awk '{printf "%f", $0}')
cpu=$(echo "scale=4; (($tts * 100))" | bc -l | awk '{printf "%f", $0}')
echo "$cpu" > $file
for value in {2..60}
do
uptime=$(cat /proc/uptime | awk '{print $1}')
uptime=${uptime%.*}
pid=$(pgrep -f $p)
ticks=$(getconf CLK_TCK)
u=$(cat /proc/$pid/stat | awk '{print $14}')
s=$(cat /proc/$pid/stat | awk '{print $15}')
cu=$(cat /proc/$pid/stat | awk '{print $16}')
cs=$(cat /proc/$pid/stat | awk '{print $17}')
starttime=$(cat /proc/$pid/stat | awk '{print $22}')
totaltime=$(($u+$s+$cu+$cs))
st=$((starttime/ticks))
seconds=$(($uptime - $st))
tt=$((totaltime/ticks))
tts=$(echo "scale=4; (($tt/$seconds))" | bc -l | awk '{printf "%f", $0}')
cpu=$(echo "scale=4; (($tts * 100))" | bc -l | awk '{printf "%f", $0}')
echo "$cpu" >> $file
sleep 1s
done
awk '{avg+=$1;} END {print avg/60}' $file