【Python运维脚本】Python监控网卡流量
2014-09-19 15:41
711 查看
#!/usr/bin/env python # -*- coding=utf-8 -*- #Using GPL v2.7 #Author: leexide@126.com #Python监控网卡流量 """ 1、实现原理:通过SNMP协议获取系统信息,再进行相应的计算和格式化,最后输出结果 2、特别注意:被监控的机器上需要支持snmp。yum install -y net-snmp*安装 """ #!/usr/bin/python import re import os #get SNMP-MIB2 of the devices def getAllitems(host,oid): sn1 = os.popen('snmpwalk -v 2c -c public ' + host + ' ' + oid).read().split('\n')[:-1] return sn1 #get network device def getDevices(host): device_mib = getAllitems(host,'RFC1213-MIB::ifDescr') device_list = [] for item in device_mib: if re.search('eth',item): device_list.append(item.split(':')[3].strip()) return device_list #get network date def getDate(host,oid): date_mib = getAllitems(host,oid)[1:] date = [] for item in date_mib: byte = float(item.split(':')[3].strip()) date.append(str(round(byte/1024,2)) + ' KB') return date if __name__ == '__main__': hosts = ['192.168.10.1','192.168.10.2'] for host in hosts: device_list = getDevices(host) inside = getDate(host,'IF-MIB::ifInOctets') outside = getDate(host,'IF-MIB::ifOutOctets') print '==========' + host + '==========' for i in range(len(inside)): print '%s : RX: %-15s TX: %s ' % (device_list[i], inside[i], outside[i]) print
相关文章推荐
- 【Python运维脚本】Python监控网卡流量
- 【Python运维脚本】Python监控网卡流量
- Python脚本实现网卡流量监控
- 网卡流量监控脚本 ( Python )
- Python脚本实现网卡流量监控
- Python 写的几个监控脚本(CPU,内存,网卡流量,负载,磁盘空间)
- nagios 监控 网卡流量 脚本
- Linux下网络流量监控工具大全,查看网卡的实时流量脚本
- 脚本实时监控网卡流量
- python脚本监控网站状态 - 赵海华_运维之路 - 51CTO技术博客
- 【Python运维脚本】Python监控磁盘
- Shell脚本监控网卡流量
- shell awk实现实时监控网卡流量脚本(常见应用二)
- shell awk实现实时监控网卡流量脚本(常见应用二)
- 【Python运维脚本】Python监控内存(swap)的使用率
- 【Python运维脚本】Python监控磁盘
- graphite,python监控网卡流量
- 监控网卡流量脚本
- shell脚本实现对网卡流量监控
- linux shell下写监控网卡流量的脚本(未完待续)