zoukankan      html  css  js  c++  java
  • 一个统计 CPU 内存 硬盘 使用率的shell脚本

    一个统计 CPU 内存 硬盘 使用率的shell脚本,供大家学习参考

    #!/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
    ",$13)}'`
      system=`echo $temp |awk '{printf("%s
    ",$14)}'`
      idle=`echo $temp |awk '{printf("%s
    ",$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
  • 相关阅读:
    POJ 1753
    POJ 3669
    POJ 1979
    HDU 1372
    Codeforces 761D
    response下载csv文件内容乱码问题
    只要没有给String[]数组new 空间,那么他就只是一个引用
    servlet中的“/”代表当前项目,html中的“/”代表当前服务器
    onkeyup的死循环问题
    OPGL+VS2017+GLFW+GLEW配置详细步骤
  • 原文地址:https://www.cnblogs.com/clarke/p/5454319.html
Copyright © 2011-2022 走看看