国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

一個用了統計CPU 內存 硬盤 使用率的shell腳本

2019-10-26 18:36:00
字體:
來源:轉載
供稿:網友

代碼如下:
#!/bin/bash
#This script is use 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 $3}'`
  nice=0
  temp=`vmstat 1 3 |tail -1`
  user=`echo $temp |awk '{printf("%s/n",$13)}'`
  system=`echo $temp |awk '{printf("%s/n",$14)}'`
  idle=`echo $temp |awk '{printf("%s/n",$15)}'`
  total=`echo|awk '{print (c1+c2)}' c1=$system c2=$user`
fi
echo "#CPU Utilization#"
echo "Total CPU  is already use: $total"
echo "CPU user   is already use: $user"
echo "CPU system is already use: $system"
echo "CPU nice   is already use: $nice"
echo "CPU idle   is already use: $idle"
echo
root_use=$(df -lh | awk 'NR==2' | awk '{print $5}')
dev_use=$(df -lh | awk 'NR==3' | awk '{print $5}')
dev_shm_use=$(df -lh | awk 'NR==4' | awk '{print $5}')
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 $3}')
memery_all=$(free | awk 'NR==2' | awk '{print $2}')
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 $3}')
swap_all=$(free | awk 'NR==4' | awk '{print $2}')
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

在開發CFS過程中需要對機器實時的內存,CPU,硬盤使用率進行監控,因為CFS跑在Linux機器上,可以利用Linux中一些相應虛擬文件進行內存CPU使用率的計算,于是編寫了以下腳本,很簡單,但是很實用。

包含三個部分,分別為硬盤使用率,內存使用率和CPU使用率。
代碼如下:
 #!/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分區,所以以此提取。
Location=/dev/sda8
Disk_Used_Rate=$(df -h | grep $Location | awk '{print $5}')
echo $Disk_Used_Rate

#memory_used_rate
LoadMemory=$(cat /proc/meminfo | awk '{print $2}')
Total=$(echo $LoadMemory | awk '{print $1}')
Free1=$(echo $LoadMemory | awk '{print $2}')
Free2=$(echo $LoadMemory | awk '{print $3}')
Free3=$(echo $LoadMemory | awk '{print $4}')

Used=`expr $Total - $Free1 - $Free2 - $Free3`

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 克东县| 马公市| 兴山县| 禹城市| 德保县| 聂拉木县| 宜君县| 牟定县| 邹城市| 灵璧县| 邵阳县| 无锡市| 岳阳县| 盈江县| 威远县| 邵阳市| 肇州县| 彩票| 桐庐县| 喀喇沁旗| 嘉义县| 泌阳县| 澎湖县| 盐山县| 长沙市| 基隆市| 泰顺县| 镇巴县| 兴和县| 松阳县| 延津县| 新余市| 九江县| 宜君县| 老河口市| 克山县| 诏安县| 紫金县| 镇坪县| 旅游| 甘德县|