Shell

推荐列表 站点导航

当前位置:首页 > 脚本编程 > Shell >

实时监测vps主机流量的shell脚本

来源:网络整理  作者:  发布时间:2020-12-21 00:49
本文介绍下,一个用于实时监测vps主机流量的shell脚本,不用iftop工具,采用纯脚本的方式。有需要的朋友参考下。...
in_old=${in}
out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $9 }' )

# edit by ym97.com/wenku

eth=$1

脚本如下:
typeset in in_old dif_in
   echo "Usage: $0  "
out=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $9 }' )
usage
typeset eth

in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $1 }' )

# usage
do

复制代码 代码示例:

exit 0

function usage
   echo "    e.g. $0 eth0 2"
方法2,就是本文要分享的这种,用shell脚本采集/proc/net/dev中的实时数据,不依赖任何安装包,对于内网linux服务器很有用。

while true
}

脚本说明:
# test network width
{
done
dif_in=$(((in-in_old)/timer))

#!/bin/bash
dif_out=$(((out-out_old)/timer))
echo "IN: ${dif_in} Byte/s OUT: ${dif_out} Byte/s "
in=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $1 }' )

方法1,可以安装iftop,通过ascii图形化显示实时流量数据,比较直观明显。

if [ $# -lt 2 ];then
参数1, 网卡设备号,一般就是 eth0;参数2,统计间隔的秒数,2 表示2秒计算一次。
typeset timer
fi
   exit 65
sleep ${timer}
流量统计单位是 Byte/s。

 

out_old=${out}

在linux中,实时流量监控不外乎两种方法。

本脚本需要二个参数。
typeset out out_old dif_out
timer=$2

相关热词: shell 主机

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://www.juheyunku.com/jiaob/shell/6411.shtml

相关文章
最新文章
PHP生成奖状 PHP生成奖状

时间:2021-01-06

python实现输入五个数并求 python实现输入五个数并求

时间:2021-01-06

php检测网站是否正常打开 php检测网站是否正常打开

时间:2021-01-05

python怎么右对齐 python怎么右对齐

时间:2021-01-05

Python3爬虫入门之Python3的安 Python3爬虫入门之Python3的安

时间:2021-01-05

如何用PHP接收http请求头信 如何用PHP接收http请求头信

时间:2021-01-05

数据库怎么连接用php写的 数据库怎么连接用php写的

时间:2021-01-05

php后缀怎么打开 php后缀怎么打开

时间:2021-01-05

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

实时监测vps主机流量的shell脚本

2020-12-21 编辑:

in_old=${in}
out_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $9 }' )

# edit by ym97.com/wenku

eth=$1

脚本如下:
typeset in in_old dif_in
   echo "Usage: $0  "
out=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $9 }' )
usage
typeset eth

in_old=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $1 }' )

# usage
do

复制代码 代码示例:

exit 0

function usage
   echo "    e.g. $0 eth0 2"
方法2,就是本文要分享的这种,用shell脚本采集/proc/net/dev中的实时数据,不依赖任何安装包,对于内网linux服务器很有用。

while true
}

脚本说明:
# test network width
{
done
dif_in=$(((in-in_old)/timer))

#!/bin/bash
dif_out=$(((out-out_old)/timer))
echo "IN: ${dif_in} Byte/s OUT: ${dif_out} Byte/s "
in=$(cat /proc/net/dev | grep $eth | sed -e "s/\(.*\)\:\(.*\)/\2/g" | awk ' { print $1 }' )

方法1,可以安装iftop,通过ascii图形化显示实时流量数据,比较直观明显。

if [ $# -lt 2 ];then
参数1, 网卡设备号,一般就是 eth0;参数2,统计间隔的秒数,2 表示2秒计算一次。
typeset timer
fi
   exit 65
sleep ${timer}
流量统计单位是 Byte/s。

 

out_old=${out}

在linux中,实时流量监控不外乎两种方法。

本脚本需要二个参数。
typeset out out_old dif_out
timer=$2

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://www.juheyunku.com/jiaob/shell/6411.shtml

相关文章

风云图片

推荐阅读

返回Shell频道首页