<html><head><title>Querying rrd's directly.</title>
</head>
<body>
<span style=" font-family:'Courier New'; font-size: 9pt;">So, I know querying the RRD isn't exactly a smokeping problem - but I think it's an appropriate place to start.<br>
<br>
I'm attempting to write a Nagios/OMD plugin.<br>
Yes, there is a smokeping plug-in currently, but the problem I'm trying to solve is this...<br>
<br>
I've had cases where latency or packet loss goes up, consistently, and I'd like to get alerts.<br>
But I don't want alerts when a single sample gets, say 3% loss, or latency jumps 30%. But if I measured that over say, 20 minutes, or an hour, or four hours - well then I could set limits that would be a lot tighter than I would for a single sample.<br>
<br>
For example, if packet loss is greater than 2% for an hour - well we've probably got a problem. Same with latency. It might go up for someone's upload/download - but if it climbs 40% for four hours, then it's a problem we ought to look at.<br>
<br>
With the smokeping plugin or Nagios's TCP probe - you can really only look at the result for a single sample [essentially], not an average. <br>
<br>
Thus, you end up setting limits that are far outside of what might actually constitute a problem, because you might have that happen for a few minutes - perhaps a few times a day - and you don't want nagios [or smokeping] to alert on all those instances. So, that means you inevitably miss events that are important.<br>
<br>
So, I'm wanting a smokeping plug-in that you can set it to average the last X number of minutes/hours/whatever of loss/latency/jitter and generate warnings/critical events.<br>
<br>
So, I need to query the RRD's and pull stats.<br>
<br>
Ok, now that I've got you so far [Thanks by the way!] - here's the problem I've got.<br>
[I'm a terrible coder, I have a short attention span, I am even worse at perl, and I hate details! So, be patient with me!]<br>
<br>
Code snippet: [I stole this off the web somewhere, I don't recall where...]<br>
---<br>
#!/usr/bin/perl -W<br>
# <br>
# <br>
<br>
use lib qw( /usr/lib/arm-linux-gnueabihf/perl5/5.20 ../lib/perl );<br>
use RRDs;<br>
use POSIX qw(strftime);<br>
<br>
#start_time is the oldest data-point, and end_time is the newest.<br>
my $cur_time = time();                # set current time<br>
my $end_time = $cur_time - 60;     # set end time to 1m ago<br>
my $start_time = $end_time - 600; # set start 10m in the past<br>
my $rrd_res = 60;<br>
my $temp_var = "";<br>
<br>
#$f_cur_time = ctime($cur_time);<br>
#$f_end_time = ctime($end_time);<br>
#$f_start_time = ctime($start_time);<br>
#$f_end_time = ctime($end_time);<br>
<br>
print "CT: $cur_time \n";<br>
print strftime("%m/%d/%Y %H:%M:%S",localtime($cur_time));<br>
print "\n \n";<br>
<br>
print "ET: $end_time \n";<br>
print strftime("%m/%d/%Y %H:%M:%S",localtime($end_time));<br>
print "\n \n";<br>
<br>
print "ST: $start_time \n";<br>
print strftime("%m/%d/%Y %H:%M:%S",localtime($start_time));<br>
print "\n \n";<br>
<br>
#exit;<br>
# fetch average values from the RRD database between start and end time<br>
my ($start,$step,$ds_names,$data) =<br>
    RRDs::fetch("/var/lib/smokeping/Some-CPE.rrd", "AVERAGE",<br>
                "-r", "$rrd_res", "-s", "$start_time", "-e", "$end_time");<br>
<br>
# save fetched values in a 2-dimensional array<br>
my $rows = 0;<br>
my $columns = 0;<br>
my $time_variable = $start;<br>
<br>
print "Start: $start : ";<br>
print strftime("%m/%d/%Y %H:%M:%S",localtime($start));<br>
print "\n \n";<br>
print "step: $step \n";<br>
<br>
print "start loop \n";<br>
print " --- \n";<br>
foreach $line (@$data) {<br>
  $vals[$rows][$columns] = $time_variable;<br>
  $temp_var = $time_variable;<br>
  print strftime("%m/%d/%Y %H:%M:%S",localtime($temp_var));<br>
  print "\n";  <br>
<br>
  $time_variable = $time_variable + $step;<br>
  $temp_var = $time_variable;<br>
  print strftime("%m/%d/%Y %H:%M:%S",localtime($temp_var));<br>
  print "\n";  <br>
  <br>
  foreach $val (@$line) {<br>
                        print " --- \n";<br>
                         print "row: $rows - col: $columns \n";<br>
                         print "Val: $val ";<br>
                          $vals[$rows][++$columns] = $val;<br>
                         print "VC: $vals[$rows][$columns] \n";<br>
                         print " --- \n";<br>
                         }<br>
  $rows++;<br>
  $columns = 0;<br>
}<br>
<br>
exit;<br>
---<br>
<br>
I've put in a bunch of print statements so I can try to figure out what's going on. [You can ignore all that...]<br>
There's also some errors in the for loop, because it parses more rows than exist in the fetch - but ignore that too. [At least for now. Or you can tell me why - if you like. I'm pretty sure I'll figure it out.]<br>
<br>
But what's interesting [at least right now] is that the first two columns have issues.<br>
Column one [or the first returned value from every row] appears to always be null.<br>
And the second always appears to be zero.<br>
[At least in my case, with my RRDs.]<br>
But I'm pretty sure it's the same with any RRD from smokeping.<br>
<br>
I may not understand [almost certainly don't] what's going on, but I'd have expected the values in the columns 3-23 to start at 1 and go through 20. [I do 20 samples in this RRD per row.]<br>
<br>
So, can someone explain why the first value [column] is always null, and the second is always zero? [These are all full resolution samples, no aggregation has occurred.]<br>
<br>
Thanks for anyone who takes a stab at it.<br>
And if you're reading Tobi, I'd be glad for your input and/or thoughts.<br>
<br>
Thanks!<br>
-Greg<br>
<br>
<br>
</span><a style=" font-family:'arial';" href="mailto:gregs@sloop.net"></a></body></html>