[mrtg] Business Hours Only hack to talker.pl
Patrick Bartkus
patrckb22 at yahoo.com
Mon Jan 10 17:42:22 MET 2005
Our situation:
We need to be able to analyze our WAN link traffic
patterns. We are getting ready to replace our
hub-and-spoke frame relay network with a MPLS network.
We need to know how much each PVC is being utilized
during business hours (8 AM to 5 PM local time). We
will then use that to size the branch local loops.
The Problem:
Plain brown wrapper MRTG shows averages over 7 X 24
period with not a clean way to segregate business hour
traffic.
My Solution:
I modified Paul Williamson & Daniel McDaniel's
excellent talker.pl. This script accumulates the
traffic over the specified time period and then ranks
the targets by bytes or percent utilization. This
gives a great Top Talker report.
I added a radio button to be able to select all hours
or only business hours. I then added code to modify
the data accumulation routine to respect that
selection.
There may be other ways to do this but this works for
me.
An Aside:
I wish I had known about
http://www.geocities.com/mrtg_daemon/toptalkers.html
when I was first setting up my configurations. He does
a great job of documenting how to set what up to get
the most out of talker.pl. Kudos to fixitdave (at)
blueyonder {dot}co{dot}uk.
My hacks [in diff -c format]:
*** talker.pl 2004-08-02 15:45:16.000000000 -0400
--- talker-wan7206_business.pl 2005-01-10
10:35:59.000000000 -0500
***************
*** 1,8 ****
! #!/usr/bin/perl
# talker.pl: Rank the talkers in a single config
file based
# on percent utilization of a circuit
#
# Version 1.1 - DJM/PCW - July 10, 2001
# Changed the periods to reflect the
correct information
# Added functionality to call talker
from command line
--- 1,10 ----
! #!/usr/bin/perl -T
# talker.pl: Rank the talkers in a single config
file based
# on percent utilization of a circuit
#
+ # Version 1.2 - PMB - January 10, 2005
+ # Added code to test for business hours
only
# Version 1.1 - DJM/PCW - July 10, 2001
# Changed the periods to reflect the
correct information
# Added functionality to call talker
from command line
***************
*** 194,199 ****
--- 202,211 ----
td($query->radio_group(-name=>'sort',
-values=>['Units','Utilization'],
-default=>'Units')));
+ print Tr(td("Hours to use:"),
+
td($query->radio_group(-name=>'hours',
+
-values=>['All Hours','Business Hours'],
+
-default=>'All')));
print end_table;
print $query->submit(-label=>'Get
rankings');
print $query->end_form;
***************
*** 205,211 ****
$sort = param('sort');
my $grouptitle =
param('group');
my $order = param('order');
! print
h1({-align=>'center'},"Top $total $grouptitle Talkers"
.br. "as of $timephrase" .br. "in $order order",hr);
my
(%topin,%topout,%perctopin,%perctopout);
my $interval =
$topparams{param('period')}[0];
my $start =
$topparams{param('period')}[1];
--- 217,226 ----
$sort = param('sort');
my $grouptitle =
param('group');
my $order = param('order');
! my $period = param('period');
! my $which_hours =
param('hours') ;
! my $business_hours_only =
$which_hours eq "Business Hours" ;
! print
h1({-align=>'center'},"$period Top $total $grouptitle
Talkers" .br. "as of $timephrase $which_hours " .br.
"in $order order",hr);
my
(%topin,%topout,%perctopin,%perctopout);
my $interval =
$topparams{param('period')}[0];
my $start =
$topparams{param('period')}[1];
***************
*** 224,232 ****
my
($start,$step,$names,$data) = RRDs::fetch @opts;
my
($intot,$outtot,$i,$intotperc,$outtotperc);
foreach my $item
(@$data) {
! $i++;
! $intot +=
$$item[0];
! $outtot +=
$$item[1];
}
if ($i > 0) {
$perctopin{$tar} = sprintf('%3f',$intot/ $i /
$targets{maxbytes}{$tar} * 100);
--- 239,264 ----
my
($start,$step,$names,$data) = RRDs::fetch @opts;
my
($intot,$outtot,$i,$intotperc,$outtotperc);
foreach my $item
(@$data) {
! ## -> PMB Test for
business hours or not
! if
($business_hours_only) {
!
@loctime = localtime($start) ;
! $start
+= $step;
!
$loctime = scalar localtime($start) ;
! if (
$loctime[2] >= 8 && $loctime[2] < 18 ) {
! ##
accumulate values
!
$i++;
!
$intot += $$item[0];
!
$outtot += $$item[1];
! }
#not business hours so don't accumulate
! } else {
! ## We
don't care what time it is, just accumulate
! $i++;
! $intot
+= $$item[0];
!
$outtot += $$item[1];
! }
}
if ($i > 0) {
$perctopin{$tar} = sprintf('%3f',$intot/ $i /
$targets{maxbytes}{$tar} * 100);
-----
Enjoy!
Patrick
=====
Patrick Bartkus, RHCE, CCNP, SCM Sr. Network Support Analyst
Atlanta, GA
If truth was not absolute, how could there be justice?
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive http://www.ee.ethz.ch/~slist/mrtg
FAQ http://faq.mrtg.org Homepage http://www.mrtg.org
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
More information about the mrtg
mailing list