美文网首页
统计cpu使用率和内存使用率

统计cpu使用率和内存使用率

作者: HaoDongZ | 来源:发表于2022-02-11 11:30 被阅读0次
    #!/bin/bash
    #计算cpu使用率
    cpu=`top -b -n1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' '{split($1, vs, ","); v=vs[length(vs)]; sub(/\s+/, "", v);sub(/\s+/, "", v); printf "%d", 100-v;}'`
    echo "cpu使用率" $cpu
    
    #统计内存使用率
    mem_used_persent=`free -m | awk -F '[ :]+' 'NR==2{printf "%d", ($2-$7)/$2*100}'`
    echo "内存使用率"  $mem_used_persent
    

    相关文章

      网友评论

          本文标题:统计cpu使用率和内存使用率

          本文链接:https://www.haomeiwen.com/subject/eqpakrtx.html