• 监控CPU、内存和硬盘利用率


    实用的shell 脚本监控 cpu_mem_disk.sh
    #!/bin/bash
    
    DATE=$(date +%F" "%H:%M)
    IP=$(ifconfig eth0 |awk '/netmask/ {print $2}')
    if ! which vmstat &> /dev/null; then
        echo "vmstat command no found, Please install procps package."
        exit 1
    fi
    
    ## CPU
    US=$(vmstat |awk 'NR==3 {print $13}')
    SY=$(vmstat |awk 'NR==3 {print $14}')
    IDLE=$(vmstat |awk 'NR==3 {print $15}')
    WAIT=$(vmstat |awk 'NR==3 {print $15}')
    USE=$(($US+$SY))
    if [ $USE -ge 50 ];then
        echo "
        Date: $DATE
        Host: $IP
        Problem: CPU utilization $USE"
    fi
    
    ## Mem
    TOTAL=$(free -m |awk '/Mem/ {print $2}')
    USE=$(free -m |awk '/Mem/ {print $3}')
    FREE=$(free -m |awk '/Mem/ {print $4+$6}')
    
    if [ $FREE -lt 1024 ]; then
        echo "
        Date: $DATE
        Host: $IP
        Problem: Total=$TOTAL,Use=$USE,Free=$FREE"
    fi
    
    #disk
    PART_USE=$(df -h |awk -F'[% ]+' 'BEGIN{OFS="="} /^/dev/ {print $1,$2,$5,$6}')
    for i in $PART_USE; do
        PART=$(echo $i |cut -d"=" -f1)
        TOTAL=$(echo $i |cut -d "=" -f2)
        USE=$(echo $i |cut -d"=" -f3)
        MOUNT=$(echo $i |cut -d"=" -f4)
        if [ $USE -gt 80 ]; then
            echo "
            Date: $DATE
            Host: $IP
            Total: $TOTAL
            Problem: $PART=$USE($MOUNT)"
        fi
    done
    
  • 相关阅读:
    Mybatisplus基本用法
    在Linux上安装JDK
    SpringCloud Hystrix(服务熔断/降级)
    easyPOI基本用法
    SpringCloud Sleuth
    SpringBoot常见的异常问题
    RabbitMQ
    SpringCloud之服务网关
    Spring Cloud alibaba
    SpringCloud之服务配置
  • 原文地址:https://www.cnblogs.com/MeiCheng/p/11805833.html
Copyright © 2020-2023  润新知