[rrd-users] RRDs::graph causes CPU overload?
Jakub Drwal
kubel at t15.ds.pwr.wroc.pl
Sat Jan 4 22:55:07 MET 2003
Hello, I just wrote new script, to monitor my memory usage.
But, after a few updates to database, my script hangs up and
eat albost 100% of my cpu. What's wrong?
Buggy script attached below:
---
#!/usr/local/bin/perl
# rrdtool memory monitor
# (c) 2003 Jakub Drwal
use lib qw(/usr/local/rrdtool/lib/perl);
use RRDs;
my $db_dir="/usr/local/rrdtool/db/";
my $db_file="mem.rrd";
my $png_dir="/home/htdocs/hades/rrd";
if (! -f $db_dir.$db_file or ! -w $db_dir.$db_file) {
RRDs::create($db_dir.$db_file,
"--start",time(),
"--step","300",
"DS:mem_used:GAUGE:600:U:U", #memory usage
"DS:mem_free:GAUGE:600:U:U",
"DS:swap_used:GAUGE:600:U:U", #swap usage
"DS:swap_free:GAUGE:600:U:U",
"DS:ps_num:GAUGE:600:U:U", #ps number
"RRA:AVERAGE:0.5:1:105120");
my $ERROR=RRDs::error();
die "$0: unable to create $db_dir.$db_file': $ERROR\n" if $ERROR;
print("Baza założona pomyslnie.\n");
exit(0);
}
$mt=`grep Mem: /proc/meminfo`;chomp($mt);$mt=~s/Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+[ 0-9]+/$1/;
$mu=`grep Mem: /proc/meminfo`;chomp($mu);$mu=~s/Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+[ 0-9]+/$2/;
$mf=`grep Mem: /proc/meminfo`;chomp($mf);$mf=~s/Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+[ 0-9]+/$3/;
$st=`grep Swap: /proc/meminfo`;chomp($st);$st=~s/Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/$1/;
$su=`grep Swap: /proc/meminfo`;chomp($su);$su=~s/Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/$2/;
$sf=`grep Swap: /proc/meminfo`;chomp($sf);$sf=~s/Swap:\s+(\d+)\s+(\d+)\s+(\d+)$/$3/;
$pn=`ps auxw|wc -l`-1;chomp($ps);
#print("mt: $mt, mu: $mu, mf: $mf\nst: $st su: $su sf: $sf\nps: $pn\n");
RRDs::update($db_dir.$db_file,"N:$mu:$mf:$su:$sf:$pn");
my $ERROR=RRDs::error();
die "$0: cannot update: $ERROR\n" if $ERROR;
#print("Chuj, generujemy\n");
RRDs::graph($png_dir."/mem_daily.png",
"-v memory usage (bytes)","-w600","-h200",
"-aPNG","-y 50:2",
"-t Memory usage on hades and number of active procs.",
"COMMENT:\\n",
"DEF:mem_u=".$db_dir.$db_file.":mem_used:AVERAGE",
"DEF:swap_u=".$db_dir.$db_file.":swap_used:AVERAGE",
"CDEF:sum_u=mem_u,swap_u,+",
"AREA:sum_u#48ff00:Total memory usage. ",
"LINE1:mem_u#ff002a:Physical memory usage ",
"LINE1:swap_u#c14fff:Virtual memory usage",
"COMMENT:\\n",
"DEF:mem_f=".$db_dir.$db_file.":mem_free:AVERAGE",
"DEF:swap_f=".$db_dir.$db_file.":swap_free:AVERAGE",
"CDEF:sum_f=mem_f,swap_f,+",
"LINE1:sum_f#00fff2:Total memory free. ",
"LINE1:mem_f#4c9cff:Physical memory free ",
"LINE1:swap_f#fffc30:Virtual memory free ",
"COMMENT:\\n","COMMENT:\\n",
"DEF:procs=".$db_dir.$db_file.":ps_num:AVERAGE",
"CDEF:procs_virt=procs,1000000,*",
"LINE1:procs_virt#000000:Number of active processes.",
"COMMENT:\\n",
"COMMENT:----------------------------------------------------------------------------------------------------------------",
"COMMENT:TOTAL memory used: ",
"COMMENT:TOTAL memory free:\\n",
"COMMENT:CURRENT:","GPRINT:sum_u:LAST:%10.0lf",
"COMMENT:AVERAGE:","GPRINT:sum_u:AVERAGE:%10.0lf",
"COMMENT: ",
"COMMENT:CURRENT:","GPRINT:sum_f:LAST:%10.0lf",
"COMMENT:AVERAGE:","GPRINT:sum_f:AVERAGE:%10.0lf",
"COMMENT:\\n",
"COMMENT: MAX:","GPRINT:sum_u:MAX:%10.0lf",
"COMMENT: MIN:","GPRINT:sum_u:MIN:%10.0lf",
"COMMENT: ",
"COMMENT: MAX:","GPRINT:sum_f:MAX:%10.0lf",
"COMMENT: MIN:","GPRINT:sum_f:MIN:%10.0lf",
"COMMENT:\\n",
"COMMENT:PHYSICAL memory used: ",
"COMMENT:PHYSICAL memory free:\\n",
"COMMENT:CURRENT:","GPRINT:mem_u:LAST:%10.0lf",
"COMMENT:AVERAGE:","GPRINT:mem_u:AVERAGE:%10.0lf",
"COMMENT: ",
"COMMENT:CURRENT:","GPRINT:mem_f:LAST:%10.0lf",
"COMMENT:AVERAGE:","GPRINT:mem_f:AVERAGE:%10.0lf",
"COMMENT:\\n",
"COMMENT: MAX:","GPRINT:mem_u:MAX:%10.0lf",
"COMMENT: MIN:","GPRINT:mem_u:MIN:%10.0lf",
"COMMENT: ",
"COMMENT:CURRENT:","GPRINT:mem_f:LAST:%10.0lf",
"COMMENT:AVERAGE:","GPRINT:mem_f:AVERAGE:%10.0lf",
"COMMENT:\\n",
"COMMENT:VIRTUAL memory used: ",
"COMMENT:VIRTUAL memory free:\\n",
"COMMENT:CURRENT:","GPRINT:swap_u:LAST:%10.0lf",
"COMMENT:AVERAGE:","GPRINT:swap_u:AVERAGE:%10.0lf",
"COMMENT: ",
"COMMENT:CURRENT:","GPRINT:swap_f:LAST:%10.0lf",
"COMMENT:AVERAGE:","GPRINT:swap_f:AVERAGE:%10.0lf",
"COMMENT:\\n",
"COMMENT: MAX:","GPRINT:swap_u:MAX:%10.0lf",
"COMMENT: MIN:","GPRINT:swap_u:MIN:%10.0lf",
"COMMENT: ",
"COMMENT:CURRENT:","GPRINT:swap_f:LAST:%10.0lf",
"COMMENT:AVERAGE:","GPRINT:swap_f:AVERAGE:%10.0lf",
"COMMENT:\\n",
);
my $ERROR=RRDs::error();
die "$0: cannot make graph: $ERROR\n" if $ERROR;
---
Thanks for your help,
Kuba
---
Experience is that marvellous thing that enables you recognize a mistake
when you make it again.
--
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