rrdtool结合apache展现

1.1 配置apache

1)DocumentRoot “/home/shanks/apache2/htdocs”

2)建立/home/shanks/apache2/htdocs/rrdtool

3)建立images、rrd目录在/home/shanks/apache2/htdocs/rrdtool下面

4)在/home/shanks/apache2/htdocs/rrdtool下面编辑create_test.sh 、graph_test.sh、update_graph.sh、update_test.sh、index.html

1.2 编辑首页和脚本

1.2.1 vim index.html

<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>

<HTML>

<HEAD>

<TITLE>RRDTool</TITLE>

<META HTTP-EQUIV=”Refresh” CONTENT=”300″>

<META HTTP-EQUIV=”Cache-Control” content=”no-cache”>

<META HTTP-EQUIV=”Pragma” CONTENT=”no-cache”>

<META HTTP-EQUIV=”Expires” CONTENT=”Tue, 09 Aug 2005 12:37:33 GMT”>

</HEAD>


<BODY bgcolor=”#ffffff” text=”#000000″ link=”#000000″ vlink=”#000000″ alink=”#000000″>

<!�C commandline was: indexmaker firewall_1.cfg �C>



<H1>Total Traffic �C TEST</H1>


<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10>

<TR>

<TD><DIV><B>Day view </B></DIV>

<DIV><IMG BORDER=1 ALT=”total_watch_dayly” SRC=”./images/total_watch_day.png”></A><BR>

</DIV>

</TD></tr>


<tr><TD><DIV>Week view<B></B></DIV>

<DIV><IMG BORDER=1 ALT=”total_watch_weekly” SRC=”./images/total_watch_week.png”></A><BR>

</SMALL></DIV>

</TD></TR>


<TR>

</TR>



<tr><TD><DIV>Month view<B></B></DIV>

<DIV><IMG BORDER=1 ALT=”total_watch_monthly” SRC=”./images/total_watch_month.png”></A><BR>

</SMALL></DIV>

</TD></TR>


<TR>

</TR>


<tr><TD><DIV>year view <B></B></DIV>

<DIV><IMG BORDER=1 ALT=”total_watch_yearly” SRC=”./images/total_watch_year.png”></A><BR>

</SMALL></DIV>

</TD></TR>


<TR>

</TR>

</TABLE>


<BR>

1.1.1 vim graph_test.sh

#!/bin/bash

DIR=/home/rrddtool/http_web

image_path=”${DIR}/images”

set 192.168.100.1 192.168.100.2

RRDFILE=”${DIR}/rrd/watch_”

DATE=`date “+%F %H:%M” `

for t in day week month year

do

rrdtool graph ${image_path}/total_watch_${t}.png \

-t “Total Traffic �CTEST ($DATE)” \

-s `date -d “-1 $t” +%s` \

-e `date -d “-5 minute” +%s` \

DEF:in1=$RRDFILE$1.rrd:in:AVERAGE \

DEF:out1=$RRDFILE$1.rrd:out:AVERAGE \

DEF:in2=$RRDFILE$2.rrd:in:AVERAGE \

DEF:out2=$RRDFILE$2.rrd:out:AVERAGE \

CDEF:IN1=in1,8,* \

CDEF:OUT1=out1,8,* \

CDEF:IN2=in2,8,* \

CDEF:OUT2=out2,8,* \

CDEF:IN1_UN=IN1,UN,0,IN1,IF \

CDEF:OUT1_UN=OUT1,UN,0,OUT1,IF \

CDEF:IN2_UN=IN2,UN,0,IN2,IF \

CDEF:OUT2_UN=OUT2,UN,0,OUT2,IF \

CDEF:IN_Total=IN1_UN,IN2_UN,+ \

CDEF:OUT_Total=OUT1_UN,OUT2_UN,+ \

COMMENT:”OUT MAX AVG MIN NOW \n” \

AREA:OUT1#8020c0:”OUT $1 ” \

GPRINT:OUT1:MAX:”%12.2lf%s” \

GPRINT:OUT1:AVERAGE:”%12.2lf%s” \

GPRINT:OUT1:MIN:”%12.2lf%s” \

GPRINT:OUT1:LAST:”%12.2lf%s\n” \

STACK:OUT2#80ffc0:”OUT $2 “ \

GPRINT:OUT2:MAX:”%12.2lf%s” \

GPRINT:OUT2:AVERAGE:”%12.2lf%s” \

GPRINT:OUT2:MIN:”%12.2lf%s” \

GPRINT:OUT2:LAST:”%12.2lf%s\n” \

COMMENT:”IN MAX AVG MIN NOW \n” \

STACK:IN1_UN#800060:”IN $1″ \

GPRINT:IN1:MAX:”%12.2lf%s” \

GPRINT:IN1:AVERAGE:”%12.2lf%s” \

GPRINT:IN1:MIN:”%12.2lf%s” \

GPRINT:IN1:LAST:”%12.2lf%s\n” \

STACK:IN2_UN#0000ff:”IN$2 ” \

GPRINT:IN2:MAX:”%12.2lf%s” \

GPRINT:IN2:AVERAGE:”%12.2lf%s” \

GPRINT:IN2:MIN:”%12.2lf%s” \

GPRINT:IN2:LAST:”%12.2lf%s\n” \

COMMENT:”\n” \

COMMENT:”OUT_TOTAL MAX AVG MIN NOW \n” \

LINE2:OUT_Total#ff0000:”OUT Total ” \

GPRINT:OUT_Total:MAX:”%12.2lf%s” \

GPRINT:OUT_Total:AVERAGE:”%12.2lf%s” \

GPRINT:OUT_Total:MIN:”%12.2lf%s” \

GPRINT:OUT_Total:LAST:”%12.2lf%s\n” \

COMMENT:”IN_TOTAL MAX AVG MIN NOW \n” \

LINE2:IN_Total#000000:”IN Total ” \

GPRINT:IN_Total:MAX:”%12.2lf%s” \

GPRINT:IN_Total:AVERAGE:”%12.2lf%s” \

GPRINT:IN_Total:MIN:”%12.2lf%s” \

GPRINT:IN_Total:LAST:”%12.2lf%s\n” \

-w 700 -h 350

done

1.1.2 vim update_graph.sh

#!/bin/sh

DIR=/home/rrddtool/http_web

${DIR}/update_test.sh

${DIR}/graph_test.sh

1.1.3 vim update_test.sh

DIR=/home/rrddtool/http_web

host=”192.168.100.1 192.168.100.2″

for ip in $host

do


#OUT_OCTETS=`snmpget -v 1 -c public $ip .1.3.6.1.2.1.2.2.1.16.2 |cut -d ” “ -f 4`

#IN_OCTETS=`snmpget -v 1 -c public $ip .1.3.6.1.2.1.2.2.1.10.2 |cut -d ” “ -f 4`


IN_OCTETS=`date +%H%M%S`

OUT_OCTETS=`date +%H%M%S`


RRD_PATH=”${DIR}/rrd/watch_${ip}.rrd”

now=`date +%s`

rrdtool update $RRD_PATH ${now}:${IN_OCTETS}:${OUT_OCTETS}

done

1.1.4 vim create_test.sh

ip=”192.168.100.1 192.168.100.2″

for ip in $ip

do

DIR=/home/rrddtool/http_web

RRDFILE=”${DIR}/rrd/watch_$ip.rrd”

rrdtool create $RRDFILE -s 300 \

DS:in:COUNTER:600:0:1000000000 \

DS:out:COUNTER:600:0:100000000 \

RRA:AVERAGE:0.5:1:14400 \

RRA:AVERAGE:0.5:6:4800 \

RRA:AVERAGE:0.5:24:1200 \

RRA:AVERAGE:0.5:288:600 \

RRA:MAX:0.5:1:14400 \

RRA:MAX:0.5:6:4800 \

RRA:MAX:0.5:24:1200 \

RRA:MAX:0.5:288:600

Done

2 写个crontab吧

*/5 * * * * /bin/bash /home/rrddtool/http_web/update_graph.sh

3 注意事项

1、apache和rrdtool的权限问题


你可能感兴趣的:(apache,rrdtool)