linux 统计网卡流量小脚本
2013-06-29 17:58
676 查看
#!/usr/bin/python
#
# zhaoyun
#
#
import re,time,sys,string
file = "/proc/net/dev"
def get_eth(eth):
ethx = []
for i in eth.split(','):
ethx.append(i)
return ethx
def get_data(ethx):
f = open(file,"r").readlines()
for i in f:
r = re.findall(r"%(ethx)s:.*." % vars(),i)
if r:
a = "".join(r).split()
input = a[0].split(':')[1:]
for input_value in input:
input = int(input_value)
output = int(a[8])
return input,output
def get_data_value(eth):
data = []
for ethx in eth:
data1 = get_data(ethx)
data.append(data1)
return data
def count_value_input(data,n,l):
count = 1
for i in data:
if count == n:
try:
for inp in i:
"1.py" 125L, 2227C written 3,2-8 Top
for i in range(1,len(dataa)+1):
inp1 = count_value_input(dataa,i,i)
inp2 = count_value_input(datab,i,i)
print_(inp1,inp2,"input",i,eth)
out1 = count_value_output(dataa,i,i)
out2 = count_value_output(datab,i,i)
print_(out1,out2,"output",i,eth)
def get_param(para,number):
c = 0
count = 0
p = []
try:
for i in sys.argv:
if i == para:
p.append(sys.argv[c+1])
count+=1
c +=1
if count == int(number):
return string.join(p)
except Exception:
return i+' Parameter Error'
def help_():
print '''
python %s -T 1 -I eth0,eth1,lo
''' %(sys.argv[0])
eth = get_param("-I",1)
Time = get_param("-T",1)
if eth and Time:
try:
Time = int(Time)
except Exception:
print "Time error"
sys.exit(2)
start_(eth,Time)
else:
help_()
使用方法:
#python 1.py -T 1 -I eth0,eth1
eth0 input :18854
eth0 output :1844
eth1 input :836
eth1 output :836
本文出自 “技术交流” 博客,请务必保留此出处http://zhaoyun.blog.51cto.com/2090116/1232740
#
# zhaoyun
#
#
import re,time,sys,string
file = "/proc/net/dev"
def get_eth(eth):
ethx = []
for i in eth.split(','):
ethx.append(i)
return ethx
def get_data(ethx):
f = open(file,"r").readlines()
for i in f:
r = re.findall(r"%(ethx)s:.*." % vars(),i)
if r:
a = "".join(r).split()
input = a[0].split(':')[1:]
for input_value in input:
input = int(input_value)
output = int(a[8])
return input,output
def get_data_value(eth):
data = []
for ethx in eth:
data1 = get_data(ethx)
data.append(data1)
return data
def count_value_input(data,n,l):
count = 1
for i in data:
if count == n:
try:
for inp in i:
"1.py" 125L, 2227C written 3,2-8 Top
for i in range(1,len(dataa)+1):
inp1 = count_value_input(dataa,i,i)
inp2 = count_value_input(datab,i,i)
print_(inp1,inp2,"input",i,eth)
out1 = count_value_output(dataa,i,i)
out2 = count_value_output(datab,i,i)
print_(out1,out2,"output",i,eth)
def get_param(para,number):
c = 0
count = 0
p = []
try:
for i in sys.argv:
if i == para:
p.append(sys.argv[c+1])
count+=1
c +=1
if count == int(number):
return string.join(p)
except Exception:
return i+' Parameter Error'
def help_():
print '''
python %s -T 1 -I eth0,eth1,lo
''' %(sys.argv[0])
eth = get_param("-I",1)
Time = get_param("-T",1)
if eth and Time:
try:
Time = int(Time)
except Exception:
print "Time error"
sys.exit(2)
start_(eth,Time)
else:
help_()
使用方法:
#python 1.py -T 1 -I eth0,eth1
eth0 input :18854
eth0 output :1844
eth1 input :836
eth1 output :836
本文出自 “技术交流” 博客,请务必保留此出处http://zhaoyun.blog.51cto.com/2090116/1232740
相关文章推荐
- Linux读取网卡流量脚本
- 统计网卡TX(发送)RX(接受)流量的shell脚本
- linux网卡流量监控脚本
- LINUX下查看网卡流量的脚本(完美修改版)【转】
- Linux读取网卡流量脚本
- shell脚本助你在linux下实时查看单网卡流量
- linux下监视网卡流量的一段脚本
- 统计网卡流量的两段shell脚本(使用ifconfig) 详细出处参考:http://www.jb51.net/article/34290.htm
- linux 网卡流量监控脚本
- linux查看网卡平均流量的脚本
- 三个监控linux网卡流量脚本
- linux统计网卡流量
- linux 查看网卡流量的shell脚本
- Linux通过shell脚本计算网卡流量
- 统计网卡流量的两段shell脚本(使用ifconfig)
- 统计网卡TX(发送)RX(接受)流量脚本
- linux下流量统计脚本
- Shell脚本 网卡流量统计(转)
- Shell脚本 网卡流量统计(转)
- linux shell awk实现实时监控网卡流量脚本