Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Net::SNMP ifHcInoctets percentage

by yorm (Initiate)
on Nov 09, 2008 at 17:24 UTC ( [id://722499]=perlquestion: print w/replies, xml ) Need Help??

yorm has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I try to calculate percentage of incoming octets and write this script:
use Net::SNMP; my $host = 'blah'; my $community = 'blah'; #my $in = '1.3.6.1.2.1.2.2.1.10.1'; my $in = '1.3.6.1.2.1.31.1.1.1.6.1'; my $speed = 155000000; my $speed_oct = $speed /8; my $session = Net::SNMP->session( -hostname=>$host, -version => 'v2c', -community => $community ); my $old_time = undef; my $old_val = undef; while (1) { my $time = time; my $result = $session->get_request( -varbindlist => [$in] ); print "ifhcinoctets=".$result->{$in}."\n"; if (defined $old_time) { my $tick = $time - $old_time; my $dif = $result->{$in} - $old_val; my $dif_ps = $dif / $tick; my $percent = ($dif_ps * 100) / $speed_oct; print "tick=$tick; speed=$speed_oct; dif=$dif; dif_ps=$dif_ps; per +cent=$percent\n" } $old_time = $time; $old_val = $result->{$in}; sleep(30); }
But results which I get are very strange. Sometimes it's more then 100%
ifhcinoctets=24017927776411 ifhcinoctets=24018477042168 tick=30; speed=19375000; dif=549265757; dif_ps=18308858.5666667; perce +nt=94.4973345376344 ifhcinoctets=24019029035603 tick=30; speed=19375000; dif=551993435; dif_ps=18399781.1666667; perce +nt=94.9666124731183 ifhcinoctets=24019747943636 tick=30; speed=19375000; dif=718908033; dif_ps=23963601.1; percent=123 +.683102451613 ifhcinoctets=24020123125963 tick=35; speed=19375000; dif=375182327; dif_ps=10719495.0571429; perce +nt=55.3264261013825 ifhcinoctets=24020662446277 tick=30; speed=19375000; dif=539320314; dif_ps=17977343.8; percent=92. +7862905806452 ifhcinoctets=24021201349899 tick=30; speed=19375000; dif=538903622; dif_ps=17963454.0666667; perce +nt=92.7146016344086 ifhcinoctets=24021715705917 tick=30; speed=19375000; dif=514356018; dif_ps=17145200.6; percent=88. +4913579354839 ifhcinoctets=24022241442925 tick=30; speed=19375000; dif=525737008; dif_ps=17524566.9333333; perce +nt=90.4493777204301 ifhcinoctets=24022964727922 tick=30; speed=19375000; dif=723284997; dif_ps=24109499.9; percent=124 +.436128516129 ifhcinoctets=24023502233465 tick=35; speed=19375000; dif=537505543; dif_ps=15357301.2285714; perce +nt=79.2634902119816 ifhcinoctets=24024040437451 tick=30; speed=19375000; dif=538203986; dif_ps=17940132.8666667; perce +nt=92.5942341505376 ifhcinoctets=24024563200840 tick=30; speed=19375000; dif=522763389; dif_ps=17425446.3; percent=89. +9377873548387 ifhcinoctets=24025070563362 tick=35; speed=19375000; dif=507362522; dif_ps=14496072.0571429; perce +nt=74.8184364239631 ifhcinoctets=24025583316106 tick=30; speed=19375000; dif=512752744; dif_ps=17091758.1333333; perce +nt=88.2155258494624 ifhcinoctets=24026093319457 tick=30; speed=19375000; dif=510003351; dif_ps=17000111.7; percent=87. +742512 ...
Could You tell me please what kind of mistake I've done? PS. I beg your pardon for my bad English

Replies are listed 'Best First'.
Re: Net::SNMP ifHcInoctets percentage
by Perlbotics (Archbishop) on Nov 09, 2008 at 18:43 UTC

    The percentage might be too high because $tick is too small. If the SNMP query costs some seconds, the nodes can count bytes further during the time required to contact the SNMP instance. Furthermore, $tick is more or less 30s plus the time to query the device during the last iteration (plus hopefully negligible computation time) - which can have the effect of giving a percentage that is too low (if the current query was fast).
    You can try a more conservative my $tick = time - $old_time; - or better - move the my $time = time;-line after the network operation.
    Update: Maybe use Time::Hires to increase precision? It would also be interesting to get the devices' local time at the moment of the query (a single query) in order to eliminate other timing/measurement-dependencies. Comment about percentage too low added.

Re: Net::SNMP ifHcInoctets percentage
by Illuminatus (Curate) on Nov 09, 2008 at 17:47 UTC
    What kind of device are you querying? You need to verify what the snmp value you are querying really means. I see you have hard-coded the speed value. Can the device burst at higher rates?
        Yes, it's realy 155Mbps POS, I has understood my error, because real speed is 155*1024*1024=162529280.
      it's cisco router. ifSpeed give me 155 000 000 and for test I hard-code it into script
Re: Net::SNMP ifHcInoctets percentage
by yorm (Initiate) on Nov 10, 2008 at 08:11 UTC
    Thank you very much for help. Thanking your advises I fix trouble: has changed speed to 162529280, has increase tick time to 1 min. Script worked

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://722499]
Approved by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-24 11:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found