network map

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
Rossco
Cacti User
Posts: 76
Joined: Sat Jan 15, 2005 4:52 pm
Location: London, England

reading of rrd values occasionally wrong

Post by Rossco »

Hi guys

Noticed your comments about having added direct support for rrd files. Was curious as I started finding that out of a network of 40 odd routers I would occasionally get in/out values on my weathermap that were reversed(10 out of the 40). After digging about I found that the values were actually coming out of cacti2weathermap.pl wrong.

To cut the story short I used the perl data::dumper module to get the structure of the array returned from the rrds::fetch module used in the cacti2weathermap script and found a way of reliably(so far....) matching the in/out data.

I'm more than happy to share the minor hacks I did with the original script someone kindly wrote, but wanted to check if I am the *only* person who got this flipped values problem? Am i? Do I simply have a weird network with a weird cacti install?

Comments welcome :-)

Cheers

Rossco
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Re: reading of rrd values occasionally wrong

Post by Howie »

Rossco wrote:I'm more than happy to share the minor hacks I did with the original script someone kindly wrote, but wanted to check if I am the *only* person who got this flipped values problem? Am i? Do I simply have a weird network with a weird cacti install?
Nope. I noticed the same thing as I was looking at adding RRD support. In the end I added an option to swap in/out for all TARGETs, just in case someone had a lot of maps already made the 'old' way, and read them the right way round by default.
Rossco
Cacti User
Posts: 76
Joined: Sat Jan 15, 2005 4:52 pm
Location: London, England

Post by Rossco »

Hi Howie

Well seeing as I wasnt alone and losing my sanity, below is what I am currently using to create my weathermap html files from the rrd data. If anyone has any suggestions, enhancements or spots any glaring errors please yell now.

I'm only graphing link speed and have no idea how this script would work using things other than traffic_in/out values, but you should be able to hack it around engough with luck.

Cheers

Ross



Code: Select all

use RRDs;
#use Data::Dumper;

$my_dir = "d:/inetpub/wwwroot/cacti/rra/";

#output weathermap files
$my_htmldir = "d:/inetpub/wwwroot/cacti/graphs/";


# read in rrd file names using grep.exe - need to rewrite using pure perl solution.
opendir RRDDIR, $my_dir or die "Impossible to open file: $!";
@rrd_files = grep /rrd/ , readdir RRDDIR;

foreach my $router (@rrd_files){

#grab an array containing the pertinent rrd information  
    my (@data1) = RRDs::fetch $my_dir.$router ,"AVERAGE","--start","now";
  
  #uncomment these lines and the use Data::Dumper line at the top, to see the data structures and check sanity.
  #$Data::Dumper::Indent = 3;
  #$Data::Dumper::Purity = 1;
  #print Dumper(@data1); 
  
    (my $name, my $ext)  = split /rrd/,$router;
  
    $weatherfile = $my_htmldir."weatherm/wea_".$name."html";

     #grab the values from the array that *should be* the value name and the value itself
	my $index1 = @data1->[2]->[0];
	my $index2 = @data1->[2]->[1];
	my $value1 = @data1->[3]->[0]->[0];
	my $value2 = @data1->[3]->[0]->[1];

	if ($index1 =~ /in\b/ig)	{  
		($in, $crap1) = split /\./, $value1;
		($out, $crap2) = split /\./, $value2;
	} else {
		($out, $crap1) = split /\./, $value1;
		($in, $crap2) = split /\./, $value2;
	}

#print out the weathermap file.
	open OUT,">$weatherfile" or die "bad luck: $!";
	print OUT "<html>\n<body>\n$router\n";
	$nice = "<!-- cuin d $in -->\n<!-- cuout d $out -->\n"; 
	print OUT $nice;
	print OUT "</body>\n</html>";
	close OUT;
	
}
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

weathermap-1.1.1hj3

Post by Howie »

Probably the final version for me (I can't think of anything else I need). Now reads RRD files directly, so you don't need cacti2weathermap.pl

http://wotsit.thingy.com/haj/cacti-weathermap.html (see the CHANGELOG towards the bottom)

I have most of a PHP version too, on the reasoning that it would have the same dependencies as cacti itself, rather than requiring you to install perl and various modules you may not have had. That doesn't do RRD reading yet, though. What I really want to do is make a map editor, probably as a PHP app, although mainly just for the fun of making it :-)
stelaras1
Cacti User
Posts: 57
Joined: Wed Nov 03, 2004 10:11 am

Post by stelaras1 »

Howie
thanx :wink:

tested it and works fine :)
rpingar
Cacti User
Posts: 86
Joined: Mon Jun 07, 2004 8:17 am

Post by rpingar »

is it possible to have a windows version?

thanks
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

rpingar wrote:is it possible to have a windows version?
http://www.activestate.com to get ActivePerl for Windows. That comes with the GD module already.

You probably would need to use the PPM utility that comes with ActivePerl to install Number::Format. Not sure how rrdtool works on Windows though.

There's a way of packaging up perl scripts into a .exe - I'll see if it's possible with RRD included.[/url]
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

rpingar wrote:is it possible to have a windows version?
So, I had a boring slow Friday afternoon... :D

I brightened it up by playing with activeperl, rrdtool, ppm and par. Below is a link to a self-contained Windows exe. You shouldn't need to have perl, rrdtool, gd or anything extra installed. One thing I learned though is that you can't use .rrd files created on FreeBSD (and presumably other unixes) on Windows, even if it's the same processor (and endianness).

It works for my test map, which is a mix of HTML data files and RRD. That's all I've done to test it. Command-line options are exactly the same as for the plain perl script.

http://wotsit.thingy.com/haj/cacti-weathermap.html
(in the download section at the bottom)
User avatar
egarnel
Cacti Pro User
Posts: 708
Joined: Thu Nov 21, 2002 8:55 am
Location: Austin, TX

Post by egarnel »

the same is true of rrd files if they are on a linux ppc box vs an x86 box. At first, I used an apple xserve running yellowdog 3.0 and then migrated to a dell 1750 running rhel 3. Found a script that would dump the rrds to xml and another that would build them back into rrds for the new platform. If anyone is interested, I'll see if I can dig it up. It may even be floating around this forum somewhere.
rpingar
Cacti User
Posts: 86
Joined: Mon Jun 07, 2004 8:17 am

Post by rpingar »

using the exe I get this error:

Can't use an undefined value as a symbol reference at C:/Perl/site/lib/GD.pm line 175, <CONF> line 97.

May you help to understand?

thanks
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

rpingar wrote:using the exe I get this error:

Can't use an undefined value as a symbol reference at C:/Perl/site/lib/GD.pm line 175, <CONF> line 97.

May you help to understand?

thanks
I know it's not a very self-explanatory error, but I think that you have specified a BACKGROUND and the image file doesn't exist. That part of GD deals with loading .png files in. Try taking out the BACKGROUND line in your weathermap.conf first, to see if it fixes it. If it does, then you need to check the name/path for your background file.
User avatar
egarnel
Cacti Pro User
Posts: 708
Joined: Thu Nov 21, 2002 8:55 am
Location: Austin, TX

Post by egarnel »

Found it
script to dump rrd into xml:
#!/bin/sh
for x in `find . -name '*.rrd'`; do
# following is all one line
cd `dirname $x` && rrdtool dump `basename $x` > `basename $x
.rrd`.xml
done


script to makr rrd from xml
#!/bin/sh
for x in `find . -name '*.xml'`; do
# following is all one line
cd `dirname $x` && rrdtool restore `basename $x` `basename
$x.xml`.rrd
done
rpingar
Cacti User
Posts: 86
Joined: Mon Jun 07, 2004 8:17 am

Post by rpingar »

seems that GD is not installed in activeperl distribution.

Howto install it on windows?

Thanks
rpingar
Cacti User
Posts: 86
Joined: Mon Jun 07, 2004 8:17 am

Post by rpingar »

you are rigth!

the background file was the problem.
Thanks
User avatar
Howie
Cacti Guru User
Posts: 5508
Joined: Thu Sep 16, 2004 5:53 am
Location: United Kingdom
Contact:

Post by Howie »

rpingar wrote:seems that GD is not installed in activeperl distribution.

Howto install it on windows?

Thanks
Are you using the .exe or just the regular script? That .exe has GD bundled up in it, along with perl and rrd. The .exe is actually a self-running zip with all the packages inside.

Google for 'gd.ppd' to find how to install it for activeperl though - you need to use the ppm tool, and tell it to look at a different site for it's packages.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest