Linux Shell View disk partition, memory usage, CPU utilization
#!/bin/bash#disk_used_ratelocation=/dev/xvdbdisk_used_rate=$ (df-h | grep $Location | awk ' {print $} ') echo "disk used Ra TE: $Disk _used_rate "#memory_used_rateLoadMemory =$ (cat/proc/meminfo | awk ' {print $} ') total=$ (echo $LoadMemory | awk ' { Print $ ') free1=$ (echo $LoadMemory | awk ' {print $} ') free2=$ (echo $LoadMemory | awk ' {print $} ') free3=$ (Echo $LoadMemor y | awk ' {print $4} ') used= ' expr $Total-$Free 1-$Free 2-$Free 3 ' used_rate= ' expr $Used/$Total *100 ' memory_used_rate= ' expr $U Sed_rate/1 ' echo ' Memory used rate: $Memory _used_rate% "interval=3cpu_num= ' Cat/proc/stat | grep cpu[0-9]-C ' start_idle= () start_total= () cpu_rate= () for ((i=0;i<${cpu_num};i++)) {start=$ (cat/proc/st at | grep "Cpu$i" | awk ' {print $ ' "$ $" "$4" "$" "$6" "$7" "$8} ') start_idle[$i]=$ (Echo ${start} | awk ' {print $4} ') start_total[$i]=$ (Echo ${start} | awk ' {printf "%.f", $1+$2+$3+$4+$5+$6+$7} ')} start=$ (cat /proc/stat | grep "CPU" | awk ' {print $ ' "$" "$4" "$" "$6" "$7" "$8} ') start_idle[${cpu_num}]=$ (Echo ${start} | awk ' {print $4} ') start_total[${cpu_num}]=$ (Echo ${start} | awk ' {printf "%.f", $1+$2+$3+$4+$5+$6+$7} ') Sleep ${inter Val} for ((i=0;i<${cpu_num};i++)) {end=$ (Cat/proc/stat | grep "cpu$i" | awk ' {print $ "" $ $ "" $4 "" $ $ "" $ 6 "" $7 "" $8} ') end_idle=$ (Echo ${end} | awk ' {print $4} ') end_total=$ (Echo ${end} | awk ' {printf "%.f", $1+$2+$3+$4+$5+$6+$7} ') idle= ' expr ${end_idle }-${start_idle[$i]} ' total= ' expr ${end_total}-${start_total[$i]} ' idle_normal= ' expr ${idle} \* 100 ' Cpu_usage= ' expr ${idle_normal}/${total} ' cpu_rate[$i]= ' expr-${cpu_usage} ' echo ' cpu$i rate: ${CP u_rate[$i]}% "} end=$ (Cat/proc/stat | grep" CPU "| awk ' {print $ ' "$ $" "$4" "$ $" "$6" "$7" "$8} ') end_idle=$ (Echo ${end} | awk ' {print $4} ') end_total=$ (Echo ${end} | awk ' {printf "%.f", $1+$2+$3+$4+$5+$6+$7} ') idle= ' expr ${end_idle}-${st art_idle[$i]} ' total= ' expr ${enD_total}-${start_total[$i]} ' idle_normal= ' expr ${idle} \* ' cpu_usage= ' expr ${idle_normal}/${total} ' Cpu_r ate[${cpu_num}]= ' expr-${cpu_usage} ' echo ' Average CPU rate: ${cpu_rate[${cpu_num}]}% ' echo-e ' \nproccess of CPU Used rate > 100% "ps-aux | awk ' $ > 1{print $2,$3,$11} '
Linux Shell View disk partition, memory usage, CPU utilization