作者 主題: 誰會用RRDTool  (閱讀 3208 次)

0 會員 與 1 訪客 正在閱讀本文。

andy2002

  • 可愛的小學生
  • *
  • 文章數: 6
    • 檢視個人資料
誰會用RRDTool
« 於: 2002-06-27 10:36 »
誰會用RRDTool??請告知使用步驟

duncanlo

  • SA 苦力組
  • 俺是博士!
  • *****
  • 文章數: 7312
    • 檢視個人資料
誰會用RRDTool
« 回覆 #1 於: 2002-06-27 13:24 »
用 Google 找 rrdtool howto 就有很多!
這東東可以表示的圖漂亮多了...

以vmstat抓系統為例
抓資料轉成DB
代碼: [選擇]
#/bin/sh
#
# vmstat RRD data grabber
#
# written for FREESCO by dingetje (webmaster@dingetje.homeip.net)
# released to the public: 12-Nov-2001
#
# put next line(s) in crontab to run every 5 min.
#
# crontab line for vmstat RRD grabber every 5 min.
#0,5,10,15,20,25,30,35,40,45,50,55 * * * * /mnt/router/packages/rrdtool/scripts/vmstatrrd > /dev/null 2> /dev/null &
#

#
# cd to the location of this script (run by crontab !)
#
cd /tmp

#
# location of RRD database
#
VM_DBASE=/var/www/html/rrdtool/demo/vmstat.rrd

if [ ! -f $VM_DBASE ]; then

        echo Creating new vmstat RRD database...

        rrdtool create $VM_DBASE \
                --step 300 \
                DS:r:GAUGE:600:0:U \
                DS:b:GAUGE:600:0:U \
                DS:w:GAUGE:600:0:U \
                DS:swpd:GAUGE:600:U:U \
                DS:free:GAUGE:600:U:U \
                DS:buff:GAUGE:600:U:U \
                DS:si:GAUGE:600:U:U \
                DS:so:GAUGE:600:U:U \
                DS:bi:GAUGE:600:U:U \
                DS:bo:GAUGE:600:U:U \
                DS:int:GAUGE:600:U:U \
                DS:cs:GAUGE:600:U:U \
                DS:user:GAUGE:600:0:100 \
                DS:system:GAUGE:600:0:100 \
                DS:idle:GAUGE:600:0:100 \
                RRA:AVERAGE:0.5:2:2000

fi

#
# collect data, but only if
#
if [ -f $VM_DBASE ]; then
   #
   # the database exists, and..
   #
   if [ -f /usr/bin/vmstat ]; then
        #
        # vmstat is installed...
        #

        # run vmstat and get the last line

        R=`/usr/bin/vmstat 120 2 | tail -1`
        set $R

        if [ ! -z "$R" ]; then
                r=$1; b=$2; w=$3; swpd=$4; free=$5; buff=$6; si=$7; so=$8; bi=$9
                shift;shift;shift;shift;shift;shift;shift;shift;shift;shift;
                bo=$1; int=$2; cs=$3; user=$4; system=$5; idle=$6

                rrdtool update $VM_DBASE \
                         --template r:b:w:swpd:free:buff:si:so:bi:bo:int:cs:user:system:idle \
                           N:$r:$b:$w:$swpd:$free:$buff:$si:$so:$bi:$bo:$int:$cs:$user:$system:$idle

        fi
   fi
fi


轉圖檔sample
代碼: [選擇]
rrdtool graph /var/www/html/rrdtool/demo/images/cpu.gif \
        --title "CPU Load" \
        --imgformat GIF \
        --upper-limit 100 \
        --lazy \
        --rigid \
        --imginfo '<IMG SRC=/rrdtool/demo/images/%s ALT="CPU">' \
        DEF:system=/var/www/html/rrdtool/demo/vmstat.rrd:system:AVERAGE \
        DEF:user=/var/www/html/rrdtool/demo/vmstat.rrd:user:AVERAGE \
        DEF:idle=/var/www/html/rrdtool/demo/vmstat.rrd:idle:AVERAGE \
        AREA:system#ff0000:"System %" \
        STACK:user#ffff00:"User %" \
        STACK:idle#00a85a:"Idle %"

rrdtool graph /var/www/html/rrdtool/demo/images/mem.gif \
        --title "Memory" \
        --imgformat GIF \
        --lazy \
        --imginfo '<IMG SRC=/rrdtool/demo/images/%s ALT="Memory">' \
        DEF:swap=/var/www/html/rrdtool/demo/vmstat.rrd:swpd:AVERAGE \
        DEF:free=/var/www/html/rrdtool/demo/vmstat.rrd:free:AVERAGE \
        DEF:buffers=/var/www/html/rrdtool/demo/vmstat.rrd:buff:AVERAGE \
        DEF:si=/var/www/html/rrdtool/demo/vmstat.rrd:si:AVERAGE \
        DEF:so=/var/www/html/rrdtool/demo/vmstat.rrd:so:AVERAGE \
        CDEF:swapmb=swap,1024,* \
        CDEF:freemb=free,1024,* \
        CDEF:bufmb=buffers,1024,* \
        CDEF:simb=si,1024,* \
        CDEF:somb=so,1024,* \
        LINE2:swapmb#ff0000:"Swap Mb" \
        LINE2:freemb#009f32:"Free Mb" \
        LINE2:bufmb#0000ff:"Buffers Mb" \
        LINE2:simb#ff7733:"Swap In" \
        LINE2:somb#3377ff:"Swap Out"

rrdtool graph /var/www/html/rrdtool/demo/images/io.gif \
        --title "Disk I/O" \
        --imgformat GIF \
        --lazy \
        --imginfo '<IMG SRC=/rrdtool/demo/images/%s ALT="Disk I/O">' \
        DEF:bi=/var/www/html/rrdtool/demo/vmstat.rrd:bi:AVERAGE \
        DEF:bo=/var/www/html/rrdtool/demo/vmstat.rrd:bo:AVERAGE \
        LINE2:bi#ff0000:"In (blocks/s)" \
        LINE2:bo#0000ff:"Out (blocks/s)"

rrdtool graph /var/www/html/rrdtool/demo/images/misc.gif \
        --title "Misc." \
        --imgformat GIF \
        --lazy \
        --imginfo '<IMG SRC=/rrdtool/demo/images/%s ALT="Misc.">' \
        DEF:cs=/var/www/html/rrdtool/demo/vmstat.rrd:cs:AVERAGE \
        DEF:intr=/var/www/html/rrdtool/demo/vmstat.rrd:int:AVERAGE \
        AREA:cs#ff3377:"Context switches/s)" \
        LINE2:intr#0000ff:"Intr/s"

duncanlo

  • SA 苦力組
  • 俺是博士!
  • *****
  • 文章數: 7312
    • 檢視個人資料
誰會用RRDTool
« 回覆 #2 於: 2002-06-27 14:01 »
忘了貼一個別人的Sample: