• 31、服务器磁盘、内存、cpu使用率监控


    31.1、监控磁盘:

     

    #!/bin/sh
    diskspace="`df -hT`"
    IFS="
    "
    disk_value="80"
    echo "文件系统 类型 容量 已用 可用 已用% 挂载点"
    for line in $diskspace;do
        disk=`echo $line | awk -v x=${disk_value} '{if((+$6>x)) print $1,$2,$3,$4,$5,$6,$7}'`
        use_disk_value="`echo $disk | awk '{print +$6}'`"
        if [ ${use_disk_value} -gt ${disk_value} ];then
            echo $disk
        fi
    done

    31.2、监控内存:

     

    #!/bin/sh
    mem_value="80"
    mem="`free -m | awk 'NR==2{printf "Memory Usage: %sMB/%sMB %.2f%%
    ",$3,$2,$3*100/$2 }'`"
    use_mem_value="`echo $mem | awk '{printf "%.2f
    ",+$4}'`"
    
    if [ `echo "${use_mem_value}>${mem_value}" | bc` -eq 1 ];then
        echo "Warning: current memory usage is $mem"
    fi
    
    ######################TestValue##########################
    echo "当前内存使用情况:${mem}"
    echo "当前内存使用百分比:${use_mem_value}"
    echo "当前内存使用百分比是否超过${mem_value}:`echo "${use_mem_value}>${mem_value}" | bc`"
    ######################################################### 

    31.3、监控cpu:

     

    #!/bin/sh
    load_value="0.7"
    cpu_load="`top -bn1 | grep "load average:" | awk '{print $NF}'`"
    cpu_num="`lscpu | grep "CPU(s):" | awk '{print $2}'`"
    cpu_load_value="`awk -v x=${cpu_load} -v y=${cpu_num} 'BEGIN{printf "%.2f
    ",x/y}'`"
    
    if [ `echo "${cpu_load_value}>${load_value}" | bc` -eq 1 ];then
        echo "WARING:Current Cpu Load IS ${cpu_load_value}"
    fi
    
    ##################################TEST_VALUE#######################################################
    echo "Cpu15分钟的平均负载:${cpu_load}"
    echo "Cpu总核数:${cpu_num}"
    echo "Cpu15分钟的平均负载占Cpu总核数的多少:${cpu_load_value}"
    echo "Cpu15分钟的平均负载占Cpu总核数的值是否大于${load_value}:`echo "${cpu_load_value}>${load_value}" | bc`"
    ###################################################################################################
  • 相关阅读:
    kubeadm部署k8s v1.18.6版本
    harbor
    kubectl常用命令
    日常运维知识点
    CentOS6.5搭建oracle11g RAC
    linux(mint)下刻录镜像到光盘
    aspectj
    NoSql系列目录
    在线考试系统源码(题库抽题&自动阅卷打分)
    java问卷调查系统源码(java+mysql)
  • 原文地址:https://www.cnblogs.com/LiuChang-blog/p/12813320.html
Copyright © 2020-2023  润新知