• centos7常规系统指标监控shell脚本


    一共两个脚本

    monitor.sh

    #!/bin/bash
    log=/var/log/`date '+%Y-%m-%d'`.monitor.log
    
    while [[ ture ]]; do
        bash `pwd`/excute.sh  >> ${log}
        sleep 10
    done
    

    excute.sh

    #!/bin/bash
    disk=sda
    ethn=ens192
    
    function ltime() {
        echo -e "
    "
        echo -e "time:		"`date '+%Y/%m/%d-%k:%M:%S'`
    }
    
    function mem() {
        #mem
        echo -e "mem_use:	"`free -m | awk 'NR==2{print $3"MB"}'`
    }
    
    function cpu() {
        #CPU
        total=`vmstat 1 5|awk '{x+=$13;y+=$14}END{print x+y}'`
        average=$(echo "scale=2;$total/5"|bc)
        echo -e "cpu_use:	$average%"
    }
    
    function disk_io() {
        #IO
        echo -e "disk_io:	"`iostat | awk 'BEGIN{disk="'"$disk"'"}{if ($1==disk) print $1" tps:"$2" kB_read/s:"$3" kB_wrtn/s:"$4;}'`
    }
    
    function network() {
        RX_pre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
        TX_pre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
        sleep 1
        RX_next=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
        TX_next=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
        RX=$((${RX_next}-${RX_pre}))
        TX=$((${TX_next}-${TX_pre}))
        if [[ $RX -lt 1024 ]];then
          RX="${RX}B/s"
        elif [[ $RX -gt 1048576 ]];then
          RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
        else
          RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
        fi
        if [[ $TX -lt 1024 ]];then
          TX="${TX}B/s"
        elif [[ $TX -gt 1048576 ]];then
          TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
        else
          TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
        fi
        echo -e "network:	$ethn 	 RX:$RX   TX:$TX "
    }
    
    ltime
    mem
    cpu
    disk_io
    network
    
  • 相关阅读:
    博客索引
    【转载】学习顺序:顶级会议 ----> 顶级期刊 ------> 基础教材(博客) / 论文复现
    【神游篇00】关于自己的日常学习记录
    【1】ML简介
    【2】Neural Network学习
    【1】NNDL简介
    【1】Deep Learning简介
    【1】PRML简介
    【1】BRML简介
    图集压缩,,命令行工具
  • 原文地址:https://www.cnblogs.com/jojoword/p/13489667.html
Copyright © 2020-2023  润新知