使用脚本来统计CPU、磁盘、内存使用率、带宽的

#!/bin/bash
#这个脚本使用来统计CPU、磁盘、内存使用率、带宽的
total=0
system=0
user=0
i=0

#带宽使用情况
time=date "+%Y-%m-%d %k:%M"
day=date "+%Y-%m-%d"
minute=date "+%k:%M"
echo “*************************************************************************” >> 123.txt
echo “统计开始时间:$day $minute” >> 123.txt

#循环五次,避免看到的是偶然的数据
echo “#带宽的使用情况:#” >>123.txt
while (( $i<5 ))
do
#原先的ifconfig eth0|sed -n "7p"|awk '{print $2}'|cut -c7-方式获取网卡的信息为空,已经注释掉
#rx_before=ifconfig eth0|sed -n "7p"|awk '{print $2}'|cut -c7-
#tx_before=ifconfig eth0|sed -n "7p"|awk '{print $6}'|cut -c7-
rx_before=$(cat /proc/net/dev | grep ‘eth’ | tr : " " | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') tx_before=(cat /proc/net/dev | grep ‘eth’ | tr : " " | awk ‘{print $10}’)
sleep 2
#rx_after=ifconfig eth0|sed -n "7p"|awk '{print $2}'|cut -c7-
#tx_after=ifconfig eth0|sed -n "7p"|awk '{print $6}'|cut -c7-
rx_after=$(cat /proc/net/dev | grep ‘eth’ | tr : " " | awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') tx_after=(cat /proc/net/dev | grep ‘eth’ | tr : " " | awk ‘{print $10}’)

rx_result= [ ( r x a f t e r − r x b e f o r e ) / 1024 / 1024 / 2 ∗ 8 ] t x r e s u l t = [(rx_after-rx_before)/1024/1024/2*8] tx_result= [(rxafterrxbefore)/1024/1024/28]txresult=[(tx_after-tx_before)/1024/1024/2*8]
echo “$time Now_In_Speed: $rx_result Mbps Now_OUt_Speed: $tx_result Mbps” >>123.txt

let “i++”
done

rx_result= ( c a t 123. t x t ∣ g r e p " (cat 123.txt|grep " (cat123.txtgrep"time"|awk '{In+=KaTeX parse error: Expected 'EOF', got '}' at position 2: 4}̲END{print In}')…(cat 123.txt|grep “$time”|awk '{Out+=KaTeX parse error: Expected 'EOF', got '}' at position 2: 7}̲END{print Out}'…(echo "scale=2; r x r e s u l t / 5 " ∣ b c ) O u t S p e e d = rx_result/5"|bc) Out_Speed= rx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值