[rrd-users] values not storing correctly

Ed Davison edavison at swbell.net
Fri Apr 5 07:37:04 MEST 2002


I am rather new to rrdtool but love it.  After having gone through the
examples I have put together a perl script to save load, cpu usage, ram and
swap usage into an rrd file.  The problem is that most of the values turn
out to be 0 as being returned by fetch and the graphs have no data on them. 
I have the update statements and the values but they are not being stored.

Here is my perl code  (sorry it is a bit long).  Can anyone help me with
this?

Ed Davison
--------------------------------------

#!/usr/bin/perl

#rrdtool create topinfo.rrd         \
#	--step 300 \
#	DS:load_now:COUNTER:600:U:U  \
#	DS:load_past1:COUNTER:600:U:U \
#	DS:load_past5:COUNTER:600:U:U \
#	DS:cpu_user:COUNTER:600:U:U \
#	DS:cpu_sys:COUNTER:600:U:U \
#	DS:cpu_nice:COUNTER:600:U:U \
#	DS:cpu_idle:COUNTER:600:U:U \
#	DS:mem_total:COUNTER:600:U:U \
#	DS:mem_used:COUNTER:600:U:U \
#	DS:mem_free:COUNTER:600:U:U \
#	DS:swap_total:COUNTER:600:U:U \
#	DS:swap_used:COUNTER:600:U:U \
#	DS:swap_free:COUNTER:600:U:U \
#	RRA:AVERAGE:0.5:1:600   \
#	RRA:AVERAGE:0.5:6:700   \
#	RRA:AVERAGE:0.5:24:775   \
#	RRA:AVERAGE:0.5:288:797  \
#	RRA:MAX:0.5:1:600     \
#	RRA:MAX:0.5:6:700     \
#	RRA:MAX:0.5:24:775     \
#	RRA:MAX:0.5:288:797

use RRDs;

$host = `hostname`;
$user = "edavison";
$rrd = "/home/$user/graphics/rrdtool/topinfo.rrd";
$rrd2 = "/home/$user/graphics/rrdtool/loadinfo.rrd";
$graphd = "/home/$user/graphics/rrdtool/cpu-day.gif";
$graphw = "/home/$user/graphics/rrdtool/cpu-week.gif";
$secs = `date +%s`;
chomp $secs;

#$eth0_net_dev = `cat /proc/net/dev | grep eth0`;
@ary = `top -b -n 1 | head -8`;

$loadline = $ary[2];
chomp $loadline;
#print $loadline."\n";
$loadline =~ s/[:,%]//g;
$loadline =~ s/ +/ /g;
#print $loadline."\n";
@loadvals = split / /, $loadline;
$load_now = $loadvals[10];
$load_past1 = $loadvals[11];
$load_past5 = $loadvals[12];

$cpuline = $ary[4];
chomp $cpuline;
#print $cpuline."\n";
$cpuline =~ s/[:,%]//g;
$cpuline =~ s/ +/ /g;
@cpuvals = split / /, $cpuline;
$cpu_user = $cpuvals[2];
$cpu_sys = $cpuvals[4];
$cpu_nice = $cpuvals[6];
$cpu_idle = $cpuvals[8];

$memline = $ary[5];
chomp $memline;
#print $memline."\n";
$memline =~ s/[:,K%]//g;
$memline =~ s/ +/ /g;
@memvals = split / /, $memline;
$mem_total = $memvals[1];
$mem_used = $memvals[3];
$mem_free = $memvals[5];

$swapline = $ary[6];
chomp $swapline;
#print $swapline."\n";
$swapline =~ s/[:K,%]//g;
$swapline =~ s/ +/ /g;
@swapvals = split / /, $swapline;
$swap_total = $swapvals[1];
$swap_used = $swapvals[3];
$swap_free = $swapvals[5];

$rrdata = $secs.":".$load_now.":".$load_past1.":".$load_past5;
$rrdata = $rrdata.":".$cpu_user.":".$cpu_sys.":".$cpu_nice.":".$cpu_idle;
$rrdata = $rrdata.":".$mem_total.":".$mem_used.":".$mem_free;
$rrdata = $rrdata.":".$swap_total.":".$swap_used.":".$swap_free;
#print $rrdata."\n";

RRDs::update $rrd, "$rrdata";
if ($ERROR = RRDs::error) {
	die "$0: unable to update `$rrd': $ERROR\n";
};

`echo $rrdata >> .topinfo.txt`;

RRDs::update $rrd2, "$secs:$load_now:$load_pas1:$load_past5";
if ($ERROR = RRDs::error) {
	die "$0: unable to update `$rrd': $ERROR\n";
};

` echo $secs:$load_now:$load_pas1:$load_past5 >> .loadinfo.txt`;

RRDs::graph "$graphd", "--start", "-86400", 
	    "--title", "CPU Usage - $host",
            "DEF:inoctets=$rrd:cpu_sys:AVERAGE", 
            "DEF:outoctets=$rrd:cpu_user:AVERAGE", 
            "AREA:inoctets#00FF00:CPU System", 
            "LINE1:outoctets#0000FF:CPU User" ;

if ($ERROR = RRDs::error) {
	print "ERROR: $ERROR\n";
};

RRDs::graph "$graphw", "--start", "-604800", 
	    "--title", "CPU Usage - $host",
            "DEF:inoctets=$rrd:cpu_sys:AVERAGE", 
            "DEF:outoctets=$rrd:cpu_user:AVERAGE", 
            "AREA:inoctets#00FF00:CPU System", 
            "LINE1:outoctets#0000FF:CPU User" ;

if ($ERROR = RRDs::error) {
	print "ERROR: $ERROR\n";
};






--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list