简单的实时监控脚本
Posted rockley
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单的实时监控脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash while true;do net=($(egrep -v "(lo|face|Inter-)" /proc/net/dev | awk -F ":" ‘{print $1}‘)) RTstart=($(egrep -v "(lo|face|Inter-)" /proc/net/dev | awk ‘{print $2,$10}‘)) sleep 1 clear RTstop=($(egrep -v "(lo|face|Inter-)" /proc/net/dev | awk ‘{print $2,$10}‘)) Rspeed=$(( ${RTstop[0]} - ${RTstart[0]} )) Tspeed=$(( ${RTstop[1]} - ${RTstart[1]} )) function speed(){ if [[ $1 -gt 1048576 ]];then speed=$(echo "scale=2; $1 / 1048576" | bc) echo -e "$2 : ${speed} M/s " elif [[ $1 -gt 1024 ]];then speed=$(echo "scale=2; $1 / 1024" | bc) echo -e "$2 : ${speed} K/s " else speed=$1 echo -e "$2 : ${speed} B/s " fi } echo "#################################" echo "#eth : $net" echo "#$(speed $Rspeed "Down")" echo "#$(speed $Tspeed "UP ")" echo "#RUNNING : $(uptime -s)" echo "#SINCE : $(uptime -p)" echo "#CPULoad : $(awk ‘{print $1,$2,$3}‘ /proc/loadavg)" echo "#$(free -h | awk ‘/Mem/ {print "MemUsed : "$3"/"$2}‘)" echo "#################################" sleep 4 done
以上是关于简单的实时监控脚本的主要内容,如果未能解决你的问题,请参考以下文章