Пример рисования графика для одного раздела:disk_usage_create_ad0s1f.sh
#!/usr/local/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin
DATABASE_DIRECTORY=/usr/local/rrd
rrdtool create $DATABASE_DIRECTORY/disk_usage_ad0s1f.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
#!/usr/local/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin
DATABASE_DIRECTORY=/usr/local/rrd
TIMESTAMP=`date +%s`
# USAGE = space_used:space_available
USAGE=`df -k | grep ad0s1f | awk '{ print $3":"$4 }'`
disk_usage_ad0s1f.sh
rrdtool update $DATABASE_DIRECTORY/disk_usage_ad0s1f.rrd $TIMESTAMP:$USAGE
disk_usage_graphs_ad0s1f.sh
#!/usr/local/bin/bash
PATH=/bin:/usr/bin:/usr/local/bin
GRAPHS_DIRECTORY=/var/www/noc/rrd/disk
DATABASE_DIRECTORY=/usr/local/rrd
HOSTNAME=`hostname`
RRDB=$DATABASE_DIRECTORY/disk_usage_ad0s1f.rrd
DISKDEV='ad0s1f'
NOW=`date +%s`
ONE_HOUR_AGO=$(($NOW-3600))
ONE_DAY_AGO=$(($NOW-86400))
ONE_WEEK_AGO=$(($NOW-604800))
ONE_MONTH_AGO=$(($NOW-2419200))
ONE_YEAR_AGO=$(($NOW-29030400))
TIMESTAMP=" Generated on `date`"
function draw_graphic()
{
rrdtool graph $GRAPHS_DIRECTORY/$1 -s $2 -e $3 -a PNG \
-v Gigabytes -t "Disk usage for $4" \
-l 0 -r \
DEF:used=$RRDB:used:AVERAGE CDEF:usedgb=used,1024,* AREA:usedgb#ff0000:"Space used" \
DEF:avail=$RRDB:avail:AVERAGE CDEF:totalgb=avail,1024,* STACK:totalgb#00CC00:"Space free" \
COMMENT:"\n" \
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"
crontab:
* * * * * /usr/local/rrd/disk_usage_ad0s1f.sh > /dev/null 2>&1
*/15 * * * * /usr/local/rrd/disk_usage_graphs_ad0s1f.sh > /dev/null 2>&1