나는 어셈블리가 snmpsharpnet 느릅 나무는 .NET의 상단에 SNMP와 함께 연주하는 것은 매우 도움이된다라는 발견.
입력 대역폭 사용량의 비율이 agiven 인터페이스에 의해 계산 될 수 I는 this article 쓴 설명에 따르면
%의 대역폭 사용량 "에서"= (((ifInOctets (T2) -ifInOctets (T1)) * 8) * 100)/(ifSpeed * (t2-t1))
다음은 샘플 코드입니다.
using System;
using System.Collections.Generic;
using System.Text;
using SnmpSharpNet;
namespace Exemple2
{
class Program
{
static void Main(string[] args)
{
/* Get an SNMP Object
*/
SimpleSnmp snmpVerb = new SimpleSnmp("192.168.1.121", 161, "public");
if (!snmpVerb.Valid)
{
Console.WriteLine("Seems that IP or comunauty is not cool");
return;
}
/* Sample of simple Get usage on ifSpeed on interface 10
* TODO : for sure you have to detect the right interface
*/
Oid oidifSpeed = new Oid(".1.3.6.1.2.1.2.2.1.5.10");
/* Getting ifSpeed
*/
Dictionary<Oid, AsnType> snmpDataS = snmpVerb.Get(SnmpVersion.Ver2, new string[] { oidifSpeed.ToString() });
if (snmpDataS != null)
Console.WriteLine("Interface speed \"{0}\" : {1}", oidifSpeed.ToString(), snmpDataS[oidifSpeed].ToString());
else
Console.WriteLine("Not Glop!");
/* Sample of simple Get usage on ifInOctets on interface 10
* TODO : for sure you have to detect the right interface
*/
Oid oidifInOctets = new Oid(".1.3.6.1.2.1.2.2.1.10.10");
Dictionary<Oid, AsnType> snmpData1;
/* Getting it for the first time
*/
snmpData1 = snmpVerb.Get(SnmpVersion.Ver2, new string[] { oidifInOctets.ToString() });
if (snmpData1 != null)
Console.WriteLine("Number of In octets \"{0}\" : {1}", oidifInOctets.ToString(), snmpData1[oidifInOctets].ToString());
else
Console.WriteLine("Not Glop!");
int missed = 0;
while (true)
{
if (missed == 0)
{
/* When you detect a non refesh data, keep the last one
*/
snmpData1 = snmpVerb.Get(SnmpVersion.Ver2, new string[] { oidifInOctets.ToString() });
if (snmpData1 != null)
Console.WriteLine("Number of In octets \"{0}\" : {1}", oidifInOctets.ToString(), snmpData1[oidifInOctets].ToString());
else
Console.WriteLine("Not Glop!");
}
/* Some Wait (less aproximative)
*/
int duration = 5;
System.Threading.Thread.Sleep(duration*1000); // duration seconds
/* Getting it for the Second time
*/
Dictionary<Oid, AsnType> snmpData2 = snmpVerb.Get(SnmpVersion.Ver2, new string[] { oidifInOctets.ToString() });
if (snmpData2 != null)
Console.WriteLine("Number of In octets \"{0}\" : {1}", oidifInOctets.ToString(), snmpData2[oidifInOctets].ToString());
else
Console.WriteLine("Not Glop!");
Counter32 I1 = new Counter32();
I1.Set(snmpData1[oidifInOctets]);
Counter32 I2 = new Counter32();
I2.Set(snmpData2[oidifInOctets]);
Counter32 speed = new Counter32();
speed.Set(snmpDataS[oidifSpeed]);
if (I2.Value == I1.Value)
{
missed += 1;
continue;
}
decimal bandWithUsage = (((decimal)(I2.Value - I1.Value) * 8) * 100)/(speed * duration * (1+missed));
Console.WriteLine("BandWith usage : {0}%", bandWithUsage);
missed = 0;
}
}
}
}
이것은 개념의 증거입니다. 이제 BackgroundWorker와 타이머를 분리해야 할 수 있습니다.
도움이되기를 바랍니다.
안부
JP
이 코드가 유망 보인다! 나는 그것을 밖으로 시도하고 결과를 게시 할 것입니다. :) –
몇 달 전 Perl과 같은 일을했지만 매력처럼 작동하지만 수면 시간이 더 길어야합니다. 그렇지 않으면 항상 0 값이됩니다. 보다 정확한 값을 원할 경우 WMI 또는 NFDump를 사용할 수 있습니다. Windows Server 클라이언트를 사용하고 있으므로 WMI를 사용할 수 있습니다. – raz3r
매력처럼 작동합니다 :) 감사합니다. –