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