สอบถามเรื่องเครื่องมือหรือโปรแกรมที่ชื่อว่า RRDTOOL ครับในส่วนของ system มันไม่ pot กราฟให้
#!/usr/bin/perl
#
# written by Evil 2008 based on code from Martin Pot 2003
#
# http://evilx99.ev.funpic.de/linux/rrdtool/rrd_system.pl
#
use RRDs;
# define location of rrdtool databases
my $rrd = '/var/lib/rrd';
# define location of images
my $img = '/var/www/html/rrdtool';
&ProcessSYSTEM("system");
sub ProcessSYSTEM
{
# process HDD
# inputs: $_[0]: description
# get hdd temp for master drive on secondary IDE channel
my $MEM_USED=`free | grep cache: | tr -s " " | cut -d " " -f3`;
# remove eol chars and white space
chomp($MEM_USED);
$MEM_USED = $MEM_USED/1024;
print "System Memory used : $MEM_USED MB\n";
my $SYSTEM_CPU_USER_TIME=`cat /proc/stat | grep "cpu " | tr -s " " | cut -d " " -f2`;
my $SYSTEM_CPU_NICE_TIME=`cat /proc/stat | grep "cpu " | tr -s " " | cut -d " " -f3`;
my $SYSTEM_CPU_SYSTEM_TIME=`cat /proc/stat | grep "cpu " | tr -s " " | cut -d " " -f4`;
my $SYSTEM_CPU_IDLE_TIME=`cat /proc/stat | grep "cpu " | tr -s " " | cut -d " " -f5`;
# remove eol chars and white space
chomp($SYSTEM_CPU_USER_TIME);
chomp($SYSTEM_CPU_NICE_TIME);
chomp($SYSTEM_CPU_SYSTEM_TIME);
chomp($SYSTEM_CPU_IDLE_TIME);
print "CPU times: user: -$SYSTEM_CPU_USER_TIME-, nice: -$SYSTEM_CPU_NICE_TIME-, system: -$SYSTEM_CPU_SYSTEM_TIME-, idle: -$SYSTEM_CPU_IDLE_TIME-\n";
# if rrdtool database doesn't exist, create it
if (! -e "$rrd/$_[0].rrd")
{
print "creating rrd database for $_[0]...\n";
RRDs::create "$rrd/$_[0].rrd",
"-s 300",
"DS:MEM_USED:GAUGE:600:0:512",
# letzten zwei Werte bestimmt Wertebereich!!!!
"DS:CPU_USER_TIME:DERIVE:600:0:10000000",
"DS:CPU_NICE_TIME:DERIVE:600:0:10000000",
"DS:CPU_SYSTEM_TIME:DERIVE:600:0:10000000",
"DS:CPU_IDLE_TIME:DERIVE:600:0:10000000",
"RRA:AVERAGE:0.5:1:576",
"RRA:AVERAGE:0.5:6:672",
"RRA:AVERAGE:0.5:24:732",
"RRA:AVERAGE:0.5:144:1460",
"RRA:MAX:0.5:1:576",
"RRA:MAX:0.5:6:672",
"RRA:MAX:0.5:24:732",
"RRA:MAX:0.5:144:1460",
"RRA:MIN:0.5:1:576",
"RRA:MIN:0.5:6:672",
"RRA:MIN:0.5:24:732",
"RRA:MIN:0.5:144:1460";
}
# # insert values into rrd
RRDs::update "$rrd/$_[0].rrd",
"-t", "MEM_USED:CPU_USER_TIME:CPU_NICE_TIME:CPU_SYSTEM_TIME:CPU_IDLE_TIME",
# "N:30:31:32:33:34";
"N:$MEM_USED:$SYSTEM_CPU_USER_TIME:$SYSTEM_CPU_NICE_TIME:$SYSTEM_CPU_SYSTEM_TIME:$SYSTEM_CPU_IDLE_TIME";
# insert value into rrd
# RRDs::update "$rrd/$_[0].rrd",
# "-t", "MEM_USED:CPU_USER_TIME:CPU_NICE_TIME:CPU_SYSTEM_TIME:CPU_IDLE_TIME",
# "N:$MEM_USED:$SYSTEM_CPU_USER_TIME:$SYSTEM_CPU_NICE_TIME:$SYSTEM_CPU_SYSTEM_TIME:$SYSTEM_CPU_IDLE_TIME";
# "N:180:91:23:33:44";
if ($ERROR = RRDs::error) { print "$0: unable to update $_[0].rrd : $ERROR\n"; }
# create graphs
&CreateGraph($_[0], "day");
&CreateGraph($_[0], "week");
&CreateGraph($_[0], "month");
&CreateGraph($_[0], "year");
}
sub CreateGraph
{
# creates graph
# inputs: $_[0]: descrption
# $_[1]: interval (ie, day, week, month, year
RRDs::graph "$img/$_[0]-$_[1].png",
# "--lazy",
"-s -1$_[1]",
"-t memory and cpu load",
"-h", "80", "-w", "600",
"-a", "PNG",
"-v MB/%",
"DEF:MEM_USED=$rrd/$_[0].rrd:MEM_USED:AVERAGE",
"LINE1:MEM_USED#0000FF:Used memory",
"GPRINT:MEM_USED:MIN: Min\\: %2.1lf",
"GPRINT:MEM_USED:MAX: Max\\: %2.1lf",
"GPRINT:MEM_USED:AVERAGE: Avg\\: %2.1lf",
"GPRINT:MEM_USED:LAST: Current\\: %2.lf MB\\n",
"DEF:CPU_USER_TIME=$rrd/$_[0].rrd:CPU_USER_TIME:AVERAGE",
"DEF:CPU_NICE_TIME=$rrd/$_[0].rrd:CPU_NICE_TIME:AVERAGE",
"DEF:CPU_SYSTEM_TIME=$rrd/$_[0].rrd:CPU_SYSTEM_TIME:AVERAGE",
"DEF:CPU_IDLE_TIME=$rrd/$_[0].rrd:CPU_IDLE_TIME:AVERAGE",
"CDEF:SUM=CPU_USER_TIME,CPU_NICE_TIME,+,CPU_SYSTEM_TIME,+,CPU_IDLE_TIME,+",
"CDEF:LOAD_TIME=SUM,CPU_IDLE_TIME,-",
"CDEF:LOAD=LOAD_TIME,SUM,/,100,*",
"CDEF:LOAD_SYSTEM=CPU_SYSTEM_TIME,SUM,/,100,*",
"LINE1:LOAD#10A010:CPU load",
"GPRINT:LOAD:MIN: Min\\: %3.1lf",
"GPRINT:LOAD:MAX: Max\\: %3.1lf",
"GPRINT:LOAD:AVERAGE: Avg\\: %3.1lf",
"GPRINT:LOAD:LAST: Current\\: %3.1lf percent\\n",
"LINE1:LOAD_SYSTEM#FF0000:CPU system load",
"GPRINT:LOAD_SYSTEM:MIN: Min\\: %3.1lf",
"GPRINT:LOAD_SYSTEM:MAX: Max\\: %3.1lf",
"GPRINT:LOAD_SYSTEM:AVERAGE: Avg\\: %3.1lf",
"GPRINT:LOAD_SYSTEM:LAST: Current\\: %3.1lf percent";
if ($ERROR = RRDs::error) { print "$0: unable to generate $_[0] graph: $ERROR\n"; }
}
เนี้ยครับมันเป็น ภาษา perl มันสร้างภาพที่เป็นกราฟจริงซึ่งมันไม่ pot ข้อมูลลงอ่ะครับ มีแต่แนวแกนเวลาอ่ะ ที่ขยับส่วนข้อมูลแต่ละช่วงเวลาไม่มีแสดงเลยครับ
จากตัวอย่างในภาพครับแกนแนวนอนที่เป็นวันและเวลา มันขยับไปตามเวลาจริงๆ แต่ข้อมูลในแกนแนวตั้งมันไม่มี ต่ผมลอง run ไฟล์ข้างต้นที่เป็น .pl แล้วมันสามารถเอาข้อมูลออกมาได้ (run in command line) จะทำยังไงให้มัน pot ข้อมูลลงได้ครับTag : - - - -
ประวัติการแก้ไข 2011-07-03 00:47:52
Date :
2011-07-03 00:43:31
By :
thanapong.y
View :
1426
Reply :
1
ภาษา Perl หาคนรู้ยากหน่อยครับ
Date :
2011-07-06 10:32:25
By :
webmaster
Load balance : Server 00