当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 1

浪子 / hf
关闭

forked from stone_wqm / hf
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
cpu.sh 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
stone_wqm 提交于 2019-05-18 12:04 . dd
#!/bin/sh
##echo user nice system idle iowait irq softirq
#cpu 432661 13295 86656 422145968 171474 233 5346
#user (432661) 从系统启动开始累计到当前时刻,用户态的CPU时间(单位:jiffies) ,不包含 nice值为负进程。1jiffies=0.01秒
#nice (13295) 从系统启动开始累计到当前时刻,nice值为负的进程所占用的CPU时间(单位:jiffies)
#system (86656) 从系统启动开始累计到当前时刻,核心时间(单位:jiffies)
#idle (422145968) 从系统启动开始累计到当前时刻,除硬盘IO等待时间以外其它等待时间(单位:jiffies)
#iowait (171474) 从系统启动开始累计到当前时刻,硬盘IO等待时间(单位:jiffies) ,
#irq (233) 从系统启动开始累计到当前时刻,硬中断时间(单位:jiffies)
#softirq (5346) 从系统启动开始累计到当前时刻,软中断时间(单位:jiffies)
CPULOG_1=$(cat /proc/stat | grep -w 'cpu' | awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8}')
SYS_IDLE_1=$(echo $CPULOG_1 | awk '{print $4}')
Total_1=$(echo $CPULOG_1 | awk '{print $1+$2+$3+$4+$5+$6+$7}')
sleep 3
CPULOG_2=$(cat /proc/stat | grep -w 'cpu' | awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8}')
SYS_IDLE_2=$(echo $CPULOG_2 | awk '{print $4}')
Total_2=$(echo $CPULOG_2 | awk '{print $1+$2+$3+$4+$5+$6+$7}')
SYS_IDLE=`expr $SYS_IDLE_2 - $SYS_IDLE_1`
Total=`expr $Total_2 - $Total_1`
SYS_USAGE=`expr $SYS_IDLE/$Total*100 |bc -l`
#scale=3为保留三位小数
echo $(printf "%.2f" `expr "scale=3; 100-$SYS_USAGE " |bc`)
1
https://gitee.com/wangbin_langzi/hf.git
git@gitee.com:wangbin_langzi/hf.git
wangbin_langzi
hf
hf
master

搜索帮助