- 论坛徽章:
- 0
|
本帖最后由 david2003 于 2017-02-04 14:35 编辑
功能:用于对流量数据的采集,依次读取throughput_info.txt文件每一行,每5分钟执行一次snmpwalk流量采集命令,以第一行为例,第一次snmpwalk -v 2c -c public 192.168.1.1 .1.3.6.1.2.1.2.2.1.10.180,执行结果的值记为变量$previousnum,将5分钟执行后得到的值记为$currentnum。其它行也是按照这种进行计算。
对throughput_portin1端口来说,要计算的流量数值,就是后一次采集的数值 与 前一次采集的差值,即$currentnum-$previousnum=$deltanum(流量包值)。需要记录最新一次执行snmpwalk采集的时间点,记为$currenttime。每5分钟采集前后端口名称$portname、端口流量差值$deltanum、及采集时间点$currenttime均需要插入到oracle数据库表中。
(1)#more throughput_info.txt (用于采集的端口名称及命令,有多行数据)
throughput_portin1 snmpwalk -v 2c -c public 192.168.1.1 .1.3.6.1.2.1.2.2.1.10.180
throughput_portout1 snmpwalk -v 2c -c public 192.168.1.1 .1.3.6.1.2.1.2.2.1.16.180
throughput_portin2 snmpwalk -v 2c -c public 192.168.1.2 .1.3.6.1.2.1.2.2.1.10.181
throughput_portout2 snmpwalk -v 2c -c public 192.168.1.2 .1.3.6.1.2.1.2.2.1.16.181
throughput_portin3 snmpwalk -v 2c -c public 192.168.1.3 .1.3.6.1.2.1.2.2.1.10.183
throughput_portout3 snmpwalk -v 2c -c public 192.168.1.3 .1.3.6.1.2.1.2.2.1.16.183
(2)throughput.sh的部分内容
#采集端口数据的时间点
$currenttime=`date +"%Y/%m/%d %H:%M:%S"`
sqlplus report/report <<- EOF
insert into tab_throughput(portname,throughputnum,currenttime) values('throughput_portin1',$deltanum,'$currenttime');
commit;
EOF
在tab_throughput有几列,portname字段对应名称(对应throughput_info.txt第1列),throughputnum字段对应$deltanum,currenttime字段对应 $currenttime
关于逐行读取throughput_info.txt的数据,并且每5分钟采集后,记录前后5分钟的差值,如何实现,请高手指点? 多谢。
|
|