Copy Code code as follows:
#!/bin/bash
#This the script is Usage for describle CPU Hard memery Utilization
Total=0
Idle=0
System=0
User=0
Nice=0
Mem=0
Vmexec=/usr/bin/vmstat
Which SAR >/dev/null 2>&1
If [$?-ne 0]
Then
Ver= ' Vmstat-v | awk ' {printf $} '
Nice=0
Temp= ' Vmstat 1 3 |tail-1 '
User= ' echo $temp |awk ' {printf ("%s\n", $)} '
System= ' echo $temp |awk ' {printf ("%s\n", $14)} '
Idle= ' echo $temp |awk ' {printf ("%s\n", $)} '
Total= ' Echo|awk ' {print (C1+C2)} ' c1= $system c2= $user '
Fi
echo "#CPU utilization#"
echo "Total CPU are already use: $total"
echo "CPU user is already use: $user"
echo "CPU system is already use: $system"
echo "CPU Nice are already use: $nice"
echo "CPU idle is already use: $idle"
Echo
root_use=$ (Df-lh | awk ' nr==2 ' | awk ' {print $} ')
dev_use=$ (Df-lh | awk ' nr==3 ' | awk ' {print $} ')
dev_shm_use=$ (Df-lh | awk ' nr==4 ' | awk ' {print $} ')
echo "#Hard utilization#"
echo "/is already use: $root _use"
echo "/dev is already use: $dev _use"
echo "/DEV/SHM is already use: $dev _shm_use"
Echo
memery_used=$ (Free | awk ' nr==2 ' | awk ' {print $} ')
memery_all=$ (Free | awk ' nr==2 ' | awk ' {print $} ')
Memery_percent=$ (echo "scale=4; $memery _used/$memery _all" | BC)
percent_part1=$ (echo $memery _percent | cut-c 2-3)
percent_part2=$ (echo $memery _percent | cut-c 4-5)
echo "#Memery utilization#"
echo "System Memery is already use: $percent _part1. $percent _part2%"
swap_used=$ (Free | awk ' nr==4 ' | awk ' {print $} ')
swap_all=$ (Free | awk ' nr==4 ' | awk ' {print $} ')
Swap_percent=$ (echo "scale=4; $swap _used/$swap _all" | BC)
swap_part1=$ (echo $swap _percent | cut-c 2-3)
swap_part2=$ (echo $swap _percent | cut-c 4-5)
echo "Swap memery is already use: $swap _part1. $swap _part2%"
Echo
In the development of CFS process requires real-time memory of the machine, CPU, hard disk usage monitoring, because the CFS running on the Linux machine, can take advantage of some of the corresponding virtual files in Linux memory CPU utilization calculation, and then wrote the following script, very simple, but very practical.
Contains three sections for hard disk usage, memory usage, and CPU usage.
Copy Code code as follows:
#!/bin/sh
#count cpu_used_rate,memory_used_rate,disk_used_rate
# @Jayson 2012-5
#disk_used_rate
#Depend on real Storage Place the parameter ' Location ' need to alter.
#本人文件主要存储于sda8分区, so to extract it.
Location=/dev/sda8
disk_used_rate=$ (df-h | grep $Location | awk ' {print $} ')
Echo $Disk _used_rate
#memory_used_rate
loadmemory=$ (Cat/proc/meminfo | awk ' {print $} ')
total=$ (echo $LoadMemory | awk ' {print $} ')
free1=$ (echo $LoadMemory | awk ' {print $} ')
free2=$ (echo $LoadMemory | awk ' {print $} ')
free3=$ (echo $LoadMemory | awk ' {print $} ')
used= ' Expr $Total-$Free 1-$Free 2-$Free 3 '
used_rate= ' expr $Used/$Total *100 | Bc-l '
memory_used_rate= ' Expr $Used _rate/1 | BC '
Echo $Memory _used_rate%
#cpu_used_rate
log1=$ (Cat/proc/stat | grep ' CPU ' | awk ' {print $ "" $ "" $ "" $ "" $ "" $ "" $} ")
sys1=$ (echo $Log 1 | awk ' {print $} ')
total1=$ (echo $Log 1 | awk ' {print $1+$2+$3+$4+$5+$6+$7} ')
Sleep 0.5
log2=$ (Cat/proc/stat | grep ' CPU ' | awk ' {print $ "" $ "" $ "" $ "" $ "" $ "" $} ")
Sys2=$ (echo $Log 2 | awk ' {print $} ')
Total2=$ (echo $Log 2 | awk ' {print $1+$2+$3+$4+$5+$6+$7} ')
sys= ' Expr $Sys 2-$Sys 1 '
This article comes from "fighting,jayson!" blog