免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2175 | 回复: 0

如何计算前后两次获取到的结果的差值 [复制链接]

论坛徽章:
0
发表于 2017-01-21 21:24 |显示全部楼层
本帖最后由 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分钟的差值,如何实现,请高手指点? 多谢。

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP