使用rrdtool画图 2009-07-30 22:49:45
分类: 系统运维
使用rrdtool画图
November 27th, 2008 | Categories: Boring | Tags: Oracle, rrdtool
| Trackback
rrdtool 很流行,画起图来确实很方便。只需要先create一个rrd数据库,再往里面update数据,就可以使用graph来画图,而且有多种options可选。
默认生成的图形也比用Perl GD画得好看。
不过RRDTOOL也很复杂,从它可以画出那么多不同种类的图片就可以知道。
简单的Perl::RRD代码
#!/usr/bin/perl -w
# This script fetches data from $rrd, creates a graph of memory
# consumption from oracle statspack history records
#
# call the RRD perl modsule
# use lib qw( /usr/local/rrdtool-1.0.41/lib/perl ../lib/perl );
#
# on windows you might need to set default font envioment variable
# $ENV{”RRD_DEFAULT_FONT”} = “C:\\WINDOWS\\FONTS\\TIMES.TTF”;
use RRDs;
my $rrd = “executecount.rrd”;
my ($starttime,$endtime,$minvalue,$maxvalue);
my $statfile = “exestats.txt”;
my $numline;
my ($timeslot,$value);
$starttime=0;
$endtime=0;
$numline=0;
$timeslot=0;
$value=0;
open(FILE,$statfile);
while()
{
chomp;
($timeslot,$value)=(split(/,/,$_));
if ($numline==0) {
$starttime=$timeslot;
}
#print “Time slot: ${timeslot} value: ${value} \n”;
$numline=$numline+1;
}
close(FILE);
$endtime=$timeslot;
# print “starttime at ${starttime} endtime at ${endtime} \n”;
my $rracount;
$rracount=$numline+10;
RRDs::create($rrd, “–start”, $starttime - 1, “–step”, 900,
“DS:index:GAUGE:900:U:U”,
“RRA:AVERAGE:0.5:1:${rracount}”
);
my $ERROR = RRDs::error;
print “ERROR unable to create ${rrd} : ${ERROR} \n” if $ERROR;
open(FILE,$statfile);
while()
{
chomp;
($timeslot,$value)=(split(/,/,$_));
RRDs::update ($rrd,”$timeslot:$value”);
$ERR=RRDs::error;
print “ERROR while updating $rrd: $ERR\n” if $ERR;
}
close(FILE);
my ($averages,$xsize,$ysize) = RRDs::graph “execute_count.png”,
“–title”, “Database free memory of large pool”,
“–font”,”DEFAULT:10:”,
“–start”, “$starttime”,
“–end”, “$endtime”,
“–imgformat”,”PNG”,
“–width=600″,
“–height=300″,
“–alt-autoscale”,
# “–x-grid”,”MINUTE:10:HOUR:1:HOUR:4:0:%X”,
# “–no-gridfit”,
“DEF:index=$rrd:index:AVERAGE”,
# “AREA:index#123456″,
“LINE1:index#ff0000:value of free large pool size (M)”,
# “–color=FRAME#CCFFFF”,
# “–color=CANVAS#CCFFFF”,
# “–color=SHADEB#9999CC”,
# “–color=BACK#CCCCCC”,
“–slope-mode”,
“–watermark”,”made by rrdtool”,
“–vertical-label”,”free large pool size (M)”,
“COMMENT: …..What a complex and powerful rrdtool …..”,
;
# print “Gifsize: ${xsize}x${ysize}\n”;
#print “Averages: “, (join “, “, @$averages);
数据输入文本类似这个,可以从perfstat中提取历史统计信息
1227076441,4094.24
1227077341,4070.92
1227078242,4059.70
1227079142,4039.84
1227080041,3936.42
1227080942,3885.93
1227081842,3869.71
1227082742,3829.21
1227083641,3762.83
1227084541,3759.83
1227085442,3693.83
1227086342,3623.54
1227087241,3528.87
……………………..
…………………….
阅读(1058) | 评论(0) | 转发(0) |
0
上一篇:使用 RRDtool 揭示 Web 性能问题
下一篇:对RRDTool的总结
相关热门文章
给主人留下些什么吧!~~
评论热议
请登录后评论。
登录 注册