Patch for bgraphs scripts, with these changes: - use /bin/sh instead of bash [bash is optional in FreeBSD] - easy configurable network interface [TODO: add support for multiple interfaces] - easy configurable multiple disks/slices support [borrowed from rc scripts] To install: wget http://www.ag0ny.com/download/bgraphs-1.1.tar.gz tar zxvf bgraphs-1.1.tar.gz cd bgraphs-1.1 patch -p1 <.../bgraphs-1.1-paulius.diff see README and bgraphs.conf for examples ;) --- bgraphs-1.1/bgraphs.conf.orig Thu Jan 16 04:06:59 2003 +++ bgraphs-1.1/bgraphs.conf Tue Apr 13 22:37:27 2004 @@ -9,3 +9,10 @@ # Hostname of your machine HOSTNAME=`hostname` #HOSTNAME='host.domain.com' + +#IFACE=ep0 +#IFACE_GREP=Link#1 +#MAXBW=192 # in kbps + +#DISK0=/dev/ad0s1a +#DISK1=/dev/ad0s4 --- bgraphs-1.1/cpu_load.sh.orig Tue Feb 18 12:04:22 2003 +++ bgraphs-1.1/cpu_load.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf TIMESTAMP=`date +%s` --- bgraphs-1.1/cpu_load_create.sh.orig Tue Feb 18 12:04:43 2003 +++ bgraphs-1.1/cpu_load_create.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf rrdtool create $DATABASE_DIRECTORY/cpu_load.rrd -s 60 \ DS:load1:GAUGE:600:0:U \ --- bgraphs-1.1/cpu_load_graphs.sh.orig Tue Feb 18 12:04:56 2003 +++ bgraphs-1.1/cpu_load_graphs.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf RRDB=$DATABASE_DIRECTORY/cpu_load.rrd NOW=`date +%s` @@ -10,7 +10,7 @@ ONE_YEAR_AGO=$(($NOW-29030400)) TIMESTAMP=" Generated on `date`" -function draw_graphic() +draw_graphic() { rrdtool graph $GRAPHS_DIRECTORY/$1 -s $2 -e $3 -a PNG \ -t "CPU load for $4" \ --- bgraphs-1.1/disk_usage.sh.orig Tue Feb 18 12:05:11 2003 +++ bgraphs-1.1/disk_usage.sh Tue Apr 13 22:20:01 2004 @@ -1,10 +1,22 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf TIMESTAMP=`date +%s` # USAGE = space_used:space_available -USAGE=`df -k | grep da0s1a | awk '{ print $3":"$4 }'` -rrdtool update $DATABASE_DIRECTORY/disk_usage.rrd $TIMESTAMP:$USAGE + +_disk=0 +while : ; do + eval _DISK_=\$DISK${_disk} + if [ -n "${_DISK_}" ]; then + DISKDEV=`basename $_DISK_` + _disk=$((${_disk} + 1)) + USAGE=`df -k | grep $_DISK_ | awk '{ print $3":"$4 }'` + rrdtool update $DATABASE_DIRECTORY/disk_usage_$DISKDEV.rrd $TIMESTAMP:$USAGE + else + break; + fi +done + --- bgraphs-1.1/disk_usage_create.sh.orig Tue Feb 18 12:05:24 2003 +++ bgraphs-1.1/disk_usage_create.sh Tue Apr 13 22:20:01 2004 @@ -1,16 +1,27 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf + +_disk=0 +while : ; do + eval _DISK_=\$DISK${_disk} + if [ -n "${_DISK_}" ]; then + DISKDEV=`basename $_DISK_` + _disk=$((${_disk} + 1)) + rrdtool create $DATABASE_DIRECTORY/disk_usage_$DISKDEV.rrd -s 60 \ + DS:used:GAUGE:600:0:U \ + DS:avail:GAUGE:600:0:U \ + RRA:AVERAGE:0.5:1:483840 \ + RRA:MIN:0.5:1440:1 \ + RRA:MAX:0.5:1440:1 \ + RRA:MIN:0.5:10080:1 \ + RRA:MAX:0.5:10080:1 \ + RRA:MIN:0.5:40320:1 \ + RRA:MAX:0.5:40320:1 \ + RRA:MIN:0.5:483840:1 \ + RRA:MAX:0.5:483840:1 + else + break; + fi +done -rrdtool create $DATABASE_DIRECTORY/disk_usage.rrd -s 60 \ - DS:used:GAUGE:600:0:U \ - DS:avail:GAUGE:600:0:U \ - RRA:AVERAGE:0.5:1:483840 \ - RRA:MIN:0.5:1440:1 \ - RRA:MAX:0.5:1440:1 \ - RRA:MIN:0.5:10080:1 \ - RRA:MAX:0.5:10080:1 \ - RRA:MIN:0.5:40320:1 \ - RRA:MAX:0.5:40320:1 \ - RRA:MIN:0.5:483840:1 \ - RRA:MAX:0.5:483840:1 --- bgraphs-1.1/disk_usage_graphs.sh.orig Tue Feb 18 12:05:42 2003 +++ bgraphs-1.1/disk_usage_graphs.sh Tue Apr 13 22:20:01 2004 @@ -1,10 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf - -RRDB=$DATABASE_DIRECTORY/disk_usage.rrd -DISK='/dev/da0s1a' -DISKDEV='da0s1a' +. /usr/local/etc/bgraphs.conf NOW=`date +%s` ONE_HOUR_AGO=$(($NOW-3600)) @@ -14,10 +10,10 @@ ONE_YEAR_AGO=$(($NOW-29030400)) TIMESTAMP=" Generated on `date`" -function draw_graphic() +draw_graphic() { rrdtool graph $GRAPHS_DIRECTORY/$1 -s $2 -e $3 -a PNG \ - -v Gigabytes -t "Disk usage for $4" \ + -v Gigabytes -t "Disk $DISKDEV usage for $4" \ -l 0 -r \ DEF:used=$RRDB:used:AVERAGE CDEF:usedgb=used,1024,* AREA:usedgb#ff8080:"Space used" \ DEF:avail=$RRDB:avail:AVERAGE CDEF:totalgb=avail,1024,* STACK:totalgb#80ff80:"Space free" \ @@ -26,7 +22,21 @@ COMMENT:"$5\n" } -draw_graphic 'disk_'$DISKDEV'_day.png' $ONE_DAY_AGO $NOW "$HOSTNAME (last 24 hours)" "$TIMESTAMP" -draw_graphic 'disk_'$DISKDEV'_week.png' $ONE_WEEK_AGO $NOW "$HOSTNAME (last week)" "$TIMESTAMP" -draw_graphic 'disk_'$DISKDEV'_month.png' $ONE_MONTH_AGO $NOW "$HOSTNAME (last month)" "$TIMESTAMP" -draw_graphic 'disk_'$DISKDEV'_year.png' $ONE_YEAR_AGO $NOW "$HOSTNAME (last year)" "$TIMESTAMP" +_disk=0 +while : ; do + eval _DISK_=\$DISK${_disk} + if [ -n "${_DISK_}" ]; then + DISKDEV=`basename $_DISK_` + _disk=$((${_disk} + 1)) + RRDB=$DATABASE_DIRECTORY/disk_usage_$DISKDEV.rrd + + draw_graphic 'disk_'$DISKDEV'_day.png' $ONE_DAY_AGO $NOW "$HOSTNAME (last 24 hours)" "$TIMESTAMP" + draw_graphic 'disk_'$DISKDEV'_week.png' $ONE_WEEK_AGO $NOW "$HOSTNAME (last week)" "$TIMESTAMP" + draw_graphic 'disk_'$DISKDEV'_month.png' $ONE_MONTH_AGO $NOW "$HOSTNAME (last month)" "$TIMESTAMP" + draw_graphic 'disk_'$DISKDEV'_year.png' $ONE_YEAR_AGO $NOW "$HOSTNAME (last year)" "$TIMESTAMP" + + else + break; + fi +done + --- bgraphs-1.1/memory.sh.orig Thu May 1 04:45:48 2003 +++ bgraphs-1.1/memory.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf TIMESTAMP=`date +%s` --- bgraphs-1.1/memory_create.sh.orig Tue Feb 18 12:06:19 2003 +++ bgraphs-1.1/memory_create.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf rrdtool create $DATABASE_DIRECTORY/memory.rrd -s 60 \ DS:free:GAUGE:600:0:U \ --- bgraphs-1.1/memory_graphs.sh.orig Tue Feb 18 12:06:45 2003 +++ bgraphs-1.1/memory_graphs.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf RRDB=$DATABASE_DIRECTORY/memory.rrd NOW=`date +%s` @@ -10,7 +10,7 @@ ONE_YEAR_AGO=$(($NOW-29030400)) TIMESTAMP=" Generated on `date`" -function draw_graphic() +draw_graphic() { rrdtool graph $GRAPHS_DIRECTORY/$1 -s $2 -e $3 -a PNG \ -t "Memory usage for $4" \ --- bgraphs-1.1/network_usage.sh.orig Tue Feb 18 12:07:03 2003 +++ bgraphs-1.1/network_usage.sh Tue Apr 13 22:20:01 2004 @@ -1,11 +1,11 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf TIMESTAMP=`date +%s` # Modify the following line so it will return two values separated by a colon: bytes_in:bytes_out -TRAFFIC=`netstat -ibI tun0 | grep giskard | awk '{ print $7":"$10 }'` +TRAFFIC=`netstat -ibI $IFACE | grep $IFACE_GREP | awk '{ print $7":"$10 }'` rrdtool update $DATABASE_DIRECTORY/network_usage.rrd $TIMESTAMP:$TRAFFIC rrdtool update $DATABASE_DIRECTORY/network_usage_averages.rrd $TIMESTAMP:$TRAFFIC --- bgraphs-1.1/network_usage_create.sh.orig Tue Feb 18 12:07:16 2003 +++ bgraphs-1.1/network_usage_create.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf rrdtool create $DATABASE_DIRECTORY/network_usage.rrd -s 60 \ DS:in:COUNTER:600:U:U \ --- bgraphs-1.1/network_usage_graphs.sh.orig Tue Feb 18 12:07:27 2003 +++ bgraphs-1.1/network_usage_graphs.sh Thu Apr 29 11:16:44 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf RRDB=$DATABASE_DIRECTORY/network_usage.rrd RRDB_AVG=$DATABASE_DIRECTORY/network_usage_averages.rrd @@ -12,11 +12,11 @@ ONE_YEAR_AGO=$(($NOW-29030400)) TIMESTAMP=" Generated on `date`" -function draw_graphic() +draw_graphic() { rrdtool graph $GRAPHS_DIRECTORY/$1 -s $2 -e $3 -a PNG\ - -v Kbps -t "Network usage for $4" \ - -r -u 256 -l -80 \ + -v kbps -t "$IFACE usage for $4" \ + -r -u $MAXBW -l -$MAXBW \ DEF:output=$RRDB:out:AVERAGE \ DEF:input=$RRDB:in:AVERAGE \ CDEF:kbpsout=output,8,*,1000,/ \ --- bgraphs-1.1/number_processes.sh.orig Thu May 1 04:45:37 2003 +++ bgraphs-1.1/number_processes.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf TIMESTAMP=`date +%s` --- bgraphs-1.1/number_processes_create.sh.orig Thu May 1 04:46:08 2003 +++ bgraphs-1.1/number_processes_create.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/sh +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf rrdtool create $DATABASE_DIRECTORY/number_processes.rrd -s 60 \ DS:numprocs:GAUGE:600:0:U \ --- bgraphs-1.1/number_processes_graphs.sh.orig Thu May 1 04:44:45 2003 +++ bgraphs-1.1/number_processes_graphs.sh Tue Apr 13 22:20:01 2004 @@ -1,6 +1,6 @@ -#!/usr/local/bin/bash +#!/bin/sh -source /etc/bgraphs.conf +. /usr/local/etc/bgraphs.conf RRDB=$DATABASE_DIRECTORY/number_processes.rrd @@ -12,7 +12,7 @@ ONE_YEAR_AGO=$(($NOW-29030400)) TIMESTAMP=" Generated on `date`" -function draw_graphic() +draw_graphic() { rrdtool graph $GRAPHS_DIRECTORY/$1 -s $2 -e $3 -a PNG \ -v Processes -t "Number of processes for $4" \