Previous page: Link Quality
Next page: Link Quality v2

Link Quality v1

Version 2.0.2

This is one of my favourite modifications, and I thought something like it may have got into the standard v2 code, but it didn't. I wanted a pictorial representation (i.e. another graph) showing the quality of my link to my internet service provider (ISP).  So I used a bit of code that I'd come across in the Coyote Linux project many years ago, and adapted it for ipcop.  This is the view I wanted:

 

1. To achieve this requires a fair bit of editing.  First in /usr/local/bin/makegraphs add a new sub-procedure updatelq


sub updatelq {
if ( ! -e "$rrdlog/lq.rrd") {
RRDs::create ("$rrdlog/lq.rrd", "--step=300",
"DS:loss:GAUGE:600:0:100",
"DS:roundtrip:GAUGE:600:0:10000",
"RRA:AVERAGE:0.5:1:576",
"RRA:AVERAGE:0.5:6:672",
"RRA:AVERAGE:0.5:24:732",
"RRA:AVERAGE:0.5:144:1460");
$ERROR = RRDs::error;
print "Error in RRD::create for link quality: $ERROR\n" if $ERROR;
}
my $packetloss=0;
my $roundtrip=0;
my $test=0;
my $LQ_GATEWAY="xxx.yyy.xxx.yyy"; <-- enter your upstream/ISP ip address here
my $NUMPINGS=3;
my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
chomp;
my @temp = split (/\/|\%|\s/, $pingoutput);
$packetloss = $temp[18];
$roundtrip = $temp[30];
RRDs::update("$rrdlog/lq.rrd", "-t", "loss:roundtrip", "N:$packetloss:$roundtrip");
$ERROR = RRDs::error;
print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
}


2. Then add another sub-procedure updatelqgraph in the same file


sub updatelqgraph {
my $period = $_[0];
my @rrd = ();

push @rrd, @{&rrd_header("lq", $period, "$Lang::tr{'lq'} ($Lang::tr{$period})", 0, 100)};
push @rrd, "-v speed ms";
push @rrd, "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE";
push @rrd, "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE";
push @rrd, "CDEF:roundavg=roundtrip,PREV(roundtrip),+,1.05,/";
push @rrd, "CDEF:lossavg=loss,PREV(loss),+,2,/";
push @rrd, "CDEF:lossd=lossavg";
push @rrd, "CDEF:loss10=loss,10,*";
push @rrd, "CDEF:lossh=loss,2,/";
push @rrd, "CDEF:r0=roundtrip,10,MIN";
push @rrd, "CDEF:r1=roundtrip,20,MIN";
push @rrd, "CDEF:r2=roundtrip,30,MIN";
push @rrd, "CDEF:r3=roundtrip,40,MIN";
push @rrd, "CDEF:r4=roundtrip,50,MIN";
push @rrd, "CDEF:r5=roundtrip,60,MIN";
push @rrd, "CDEF:r6=roundtrip,70,MIN";
push @rrd, "CDEF:r7=roundtrip,80,MIN";
push @rrd, "CDEF:r8=roundtrip,90,MIN";
push @rrd, "CDEF:r9=roundtrip,100,MIN";
push @rrd, "AREA:roundtrip#035203:100+ ms";
push @rrd, "AREA:r9#0F620F:90-100 ms";
push @rrd, "AREA:r8#1C741C:80-90 ms";
push @rrd, "AREA:r7#288528:70-80 ms";
push @rrd, "AREA:r6#359735:60-70 ms";
push @rrd, "AREA:r5#42A942:50-60 ms";
push @rrd, "AREA:r4#4FBA4F:40-50 ms";
push @rrd, "AREA:r3#5BCC5B:30-40 ms";
push @rrd, "AREA:r2#68DD68:20-30 ms";
push @rrd, "AREA:r1#74EE74:10-20 ms";
push @rrd, "AREA:r0#80FF80:-10 ms";
push @rrd, "AREA:lossh#FF0000:Packet loss %\\j";
push @rrd, "LINE1:roundtrip#035203:";


push @rrd, "GPRINT:roundtrip:MAX:$Lang::tr{'maximal'}  $Lang::tr{'linkqrt'}\\:%3.2lf ms";
push @rrd, "GPRINT:roundtrip:AVERAGE:$Lang::tr{'average'} $Lang::tr{'linkqrt'}\\:%3.2lf ms";
push @rrd, "GPRINT:roundtrip:LAST:$Lang::tr{'current'} $Lang::tr{'linkqrt'}\\:%3.2lf ms\\j";

push @rrd, "GPRINT:loss:MAX:$Lang::tr{'maximal'}  $Lang::tr{'linkqls'}\\:%3.2lf%%";
push @rrd, "GPRINT:loss:AVERAGE:$Lang::tr{'average'} $Lang::tr{'linkqls'}\\:%3.2lf%%";
push @rrd, "GPRINT:loss:LAST:$Lang::tr{'current'} $Lang::tr{'linkqls'}\\:%3.2lf%%\\j";

push @rrd, @{&rrd_lastupdate()};
RRDs::graph(@rrd);

$ERROR = RRDs::error;
print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
}

 

3. Once again, in /usr/local/bin/makegraphs, near the bottom of the file add these lines:


###
### System graphs
###

updatelq();
sleep 2;
updatelqgraph("day");
updatelqgraph("week");
updatelqgraph("month");
updatelqgraph("year");

updatecpudata();
updatecpugraph("day");
updatecpugraph("week");
updatecpugraph("month");
updatecpugraph("year");

 

4. Add a new file /var/ipcop/addons/lang/linkquality.en.pl that has the following text in it.  This is used to provide appropriate language translations shouldl you wish to provide the modification in other languages,


# Added for link quality text
%tr = ( %tr,
'LinkQ' => 'Link Quality',
'lq' => 'Link Quality',
'linkqrt' => 'Time',
'linkqls' => 'Pkt Loss',
'hour' => 'Hour',
);

 

5. For this new language file to be considered you'll need to run the following command: rebuildlangtexts

6. Next we are going to make some changes, so that we can see our graphs.  This involves editing /home/httpd/cgi-bins/graphs.cgi. Make the following (green) additions to the file


$ENV{'QUERY_STRING'} =~ s/&//g;
@cgigraphs = split(/graph=/,$ENV{'QUERY_STRING'});
$cgigraphs[1] = '' unless defined $cgigraphs[1];

if ($cgigraphs[1] =~ /(network|GREEN|BLUE|ORANGE|RED|lq)/) {
&Header::openpage($Lang::tr{'network traffic graphs'}, 1, '');
}
else {
&Header::openpage($Lang::tr{'system graphs'}, 1, '');
}
&Header::openbigbox('100%', 'left');

if ($cgigraphs[1] =~ /(GREEN|BLUE|ORANGE|RED|cpu|memory|diskuse|disk|lq)/) {
# Display 1 specific graph

my $graph = $cgigraphs[1];
my ($graphname, $count) = split('_', lc($graph));
my $back = '';
my $title = '';
if ($graph =~ /(GREEN|BLUE|ORANGE|RED|lq)/) {
$title = ($count >= 2) ? $Lang::tr{$graphname}." ".$count : $Lang::tr{$graphname};
$back = "<a href='/cgi-bin/graphs.cgi?graph=network'>";
$title = $Lang::tr{'lq'} if ($graph eq 'lq');
}
else {
$title = $Lang::tr{'cpu usage'} if ($graph eq 'cpu');
$title = $Lang::tr{'memory usage'} if ($graph eq 'memory');

 

7. and a bit further down in the same file, these changes:


elsif ($cgigraphs[1] =~ /network/) {
# Display network graphs
push (@graphs, ("lq"));
for my $color ('GREEN', 'ORANGE', 'BLUE') {
my $icount = $netsettings{"${color}_COUNT"};
while($icount > 0) {
push (@graphs, ("${color}_${icount}"));
$icount--;
}

 

8. If you want even finer detail, alter sub-procedure updatelqgraph in /usr/local/bin/makegraphs as below:


sub updatelqgraph {
my $period = $_[0];
my @rrd = ();

push @rrd, @{&rrd_header("lq", $period, "$Lang::tr{'lq'} ($Lang::tr{$period})", -1,-1)};
push @rrd, "-v speed ms";
push @rrd, "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE";
push @rrd, "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE";
push @rrd, "CDEF:roundavg=roundtrip,PREV(roundtrip),+,1.05,/";
push @rrd, "CDEF:lossavg=loss,PREV(loss),+,2,/";
push @rrd, "CDEF:lossd=lossavg";
push @rrd, "CDEF:loss10=loss,10,*";
push @rrd, "CDEF:lossh=loss,2,/";

result:



^Top
Previous page: Link Quality
Next page: Link Quality v2