snmp switch traffic交换机带宽

上代码

 1 <?php
 2 function getstr1($strall,$str1,$str2,$html_charset='utf-8'){
 3     $i1=mb_strpos($strall,$str1,0,$html_charset);
 4     if(!is_int($i1)){return '';}
 5     $i1R=$i1+mb_strlen($str1,$html_charset);
 6     $i2=mb_strpos($strall,$str2,$i1+mb_strlen($str1,$html_charset),$html_charset);
 7     if(!is_int($i2)){return '';}
 8     return(mb_substr($strall,$i1R,$i2-$i1R,$html_charset));
 9 }
10 class traffic{
11     private $lastArr=array();
12     function __construct(){
13         $this->lastArr['time']=0;
14         $this->lastArr['out']=0;
15         $this->lastArr['in']=0;
16     }
17     function doinfo($time,$in,$out){
18         $timeI=$time-$this->lastArr['time'];
19         $outI=$out-$this->lastArr['out'];
20         if($outI<0)$outI+=pow(2,32);
21         $inI=$in-$this->lastArr['in'];
22         if($inI<0)$inI+=pow(2,32);
23         $strOut=number_format($outI/$timeI/1024/1024,2);
24         $strIn=number_format($inI/$timeI/1024/1024,2);
25         echo 'Out: '.$strOut.'MB/s,  In: '.$strIn."MB/s\n";
26         $this->lastArr['time']=$time;
27         $this->lastArr['out']=$out;
28         $this->lastArr['in']=$in;
29     }
30 }
31 $session = new SNMP(SNMP::VERSION_2C, "10.105.1.1", "public");
32 $arr=array();
33 $arr[]='iso.3.6.1.2.1.1.3.0';
34 $n=6;
35 $arr[]='iso.3.6.1.2.1.2.2.1.10.'.$n;//in
36 $arr[]='iso.3.6.1.2.1.2.2.1.16.'.$n;//out
37 $traffic=new traffic();
38 while(1){
39     $p=$session->get($arr);
40     $timeticks=$p['iso.3.6.1.2.1.1.3.0'];
41     $timeticks=getstr1($timeticks,'(',')');
42     $timeticks=$timeticks/100;
43     $iIn=$p['iso.3.6.1.2.1.2.2.1.10.6'];
44     $iIn=explode(': ',$iIn)[1];
45     $iIn=floatval($iIn);
46     $iOut=$p['iso.3.6.1.2.1.2.2.1.16.6'];
47     $iOut=explode(': ',$iOut)[1];
48     $iOut=floatval($iOut);
49     $traffic->doinfo($timeticks,$iIn,$iOut);
50     sleep(2);
51 }
52 $session->close();

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
STG (SNMP Traffic Grapher) version 1.4.5 Copyright (C) 2000 Leonid Mikhailov This freeware utility allows monitoring of supporting SNMPv1 and SNMPv2c devices including Cisco, Livingstone, Riverstone etc. Intended as fast aid for network administrators who need prompt access to current information about state of network equipment. Copyright In brief: You may use STG for any commercial and non commercial purpose. You may distribute STG for free. You may charge a fee for the physical act of transferring a copy only. This program is distributed WITHOUT ANY WARRANTY. Use it at your own risk. I cannot guarantee accuracy of displayed data. I am not liable to you for any possible damages etc... Source code is not available. Features: Single graph displays changes of two configurable SNMP variables with display of Current, Average, Maximum values. Screen snapshot: http://www.chat.ru/~leonidvm/stg.jpg Could be downloaded from: http://www.chat.ru/~leonidvm/ ftp://ftp.naytov.com/pub/stg/ Newer versions will be there too. STG was written as an add-on for MRTG application by Tobias Oetiker. MRTG (http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html) is absolutely necessary for every network and system administrator. It provides SNMP monitoring of any number devices simultaneously. However during my duties I often have to check state of ports on different routers that are not always in my domain and setting MRTG configuration takes some time. And does not allow to see last second changes in traffic. That's why STG was written. It allows monitoring of SNMP devices with different update periods starting from 0.01s so you could see what's happening right now. Also STG could be useful during network problems troubleshooting. It runs on MS Windows 2000, Windows NT 4.0, Windows 98 and Windows Millenium. To run it on WinNT 4.0 you may need mgmtapi.dll and mib.bin (see below) To run it on Win98 and Millenium you will need mg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值