[smokeping-users] Standard Deviation in Smokeping
Rui Meireles
rmeireles at tec.dsr.telecom.pt
Wed Jan 21 19:41:35 CET 2009
Thanks Tobi. Using that function (calc_stddev) and digging Smokeping.pm I
was able to make a script to calculate all the values shown in the Legend of
"Overview graphs".
Here's what I did, it might help someone:
(I cannot be a sponsor, but I'll look at your Amazon wishlist ;) )
Regards,
Rui
##################################################################
#!/usr/bin/perl -w
use strict;
my $rrd = "/usr/smokeping/data/WAN/MPLS/CR-PCS1.rrd";
my $i = 0; # No slaves
my $max = 100000;
my $interval_s = "-s -86400"; # 1 day
my @G = ();
# Determine number of datasources
my $pings = 0;
my $cmd1 = "/usr/bin/rrdtool info $rrd |grep \"ds\\[ping\"";
my @out = `$cmd1`;
foreach(@out) {
# Search last datasource. Ex: ds[ping20]
if(/^ds\[ping(\d+)\]/) {
$pings = $1 if($1 > $pings);
}
}
# Fetch info
push @G,
"/usr/bin/rrdtool graph $rrd $interval_s",
"DEF:median$i=${rrd}:median:AVERAGE",
"DEF:loss$i=${rrd}:loss:AVERAGE",
"CDEF:ploss$i=loss$i,$pings,/,100,*",
"CDEF:dm$i=median$i,0,$max,LIMIT",
calc_stddev($rrd,$i,$pings),
"CDEF:dmlow$i=dm$i,sdev$i,2,/,-",
"CDEF:s2d$i=sdev$i",
"VDEF:avmed$i=median$i,AVERAGE",
"VDEF:avsd$i=sdev$i,AVERAGE",
"CDEF:msr$i=median$i,POP,avmed$i,avsd$i,/",
"VDEF:avmsr$i=msr$i,AVERAGE",
"PRINT:avmed$i:%lf",
"PRINT:ploss$i:AVERAGE:%lf",
"PRINT:avsd$i:%lf",
"PRINT:avmsr$i:%lf";
my $cmd2 = join(" ", @G);
my $out = `$cmd2`;
print $out;
sub calc_stddev {
my $rrd = shift;
my $id = shift;
my $pings = shift;
my @G = map
{("DEF:pin${id}p${_}=${rrd}:ping${_}:AVERAGE","CDEF:p${id}p${_}=pin${id}p${_
},UN,0,pin${id}p${_},IF")} 1..$pings;
push @G, "CDEF:pings${id}="."$pings,p${id}p1,UN,".join(",",map
{"p${id}p$_,UN,+"} 2..$pings).",-";
push @G, "CDEF:m${id}="."p${id}p1,".join(",",map {"p${id}p$_,+"}
2..$pings).",pings${id},/";
push @G, "CDEF:sdev${id}=p${id}p1,m${id},-,DUP,*,".join(",",map
{"p${id}p$_,m${id},-,DUP,*,+"} 2..$pings).",pings${id},/,SQRT";
return @G;
}
##################################################################
-----Original Message-----
From: Tobias Oetiker [mailto:tobi at oetiker.ch]
Sent: quarta-feira, 21 de Janeiro de 2009 16:01
To: Rui Meireles
Cc: smokeping-users at lists.oetiker.ch
Subject: RE: [smokeping-users] Standard Deviation in Smokeping
Today Rui Meireles wrote:
> Tobi,
>
> Thanks a lot for the quick answer.
>
> I hadn't notice the difference between SD in Overview graphs and SD in
> Detail Graphs. Now I get it!
>
> What I need is exactly the value "av sd" that is being shown in the
Overview
> graphs. If you could help me with the rrdtool command that I should use to
> fetch that value, I would be most grateful, since I've already been
> "digging" smokeping.cgi but haven't found how to do it yet.
the heart of the operation is this function here:
sub calc_stddev {
my $rrd = shift;
my $id = shift;
my $pings = shift;
my @G = map
{("DEF:pin${id}p${_}=${rrd}:ping${_}:AVERAGE","CDEF:p${id}p${_}=pin${id}p${_
},UN,0,pin${id}p${_},IF")} 1..$pings;
push @G, "CDEF:pings${id}="."$pings,p${id}p1,UN,".join(",",map
{"p${id}p$_,UN,+"} 2..$pings).",-";
push @G, "CDEF:m${id}="."p${id}p1,".join(",",map {"p${id}p$_,+"}
2..$pings).",pings${id},/";
push @G, "CDEF:sdev${id}=p${id}p1,m${id},-,DUP,*,".join(",",map
{"p${id}p$_,m${id},-,DUP,*,+"} 2..$pings).",pings${id},/,SQRT";
return @G;
}
> Congratulations on this (and many other) projects, they sure are priceless
> tools!
well if you want to encurrage future development of the tools, you are
welcome to become a sponsor:
there are awfully few sponsors for the smokeping project
http://oss.oetiker.ch/smokeping/sponsors.en.html
cheers
tobi
--
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland
http://it.oetiker.ch tobi at oetiker.ch ++41 62 775 9902 / sb: -9900
More information about the smokeping-users
mailing list