Source

woocode / rrdtool / mem.sh

#!/bin/sh

rrdtool create memory.rrd \
    --start N --step 300 \
    DS:active:GAUGE:600:0:4000000 \
    DS:inactive:GAUGE:600:0:4000000 \
    DS:free:GAUGE:600:0:4000000 \
    RRA:MIN:0.5:12:1440 \
    RRA:MAX:0.5:12:1440 \
    RRA:AVERAGE:0.5:1:1440


update() {
    _ACTIVE=`cat /proc/meminfo | grep Active: | awk '{print $2}'`
    _INACTIVE=`cat /proc/meminfo | grep Inactive: | awk '{print $2}'`
    _MEMFREE=`cat /proc/meminfo | grep MemFree: | awk '{print $2}'`
    _TS=`perl -e 'print time'`
    rrdtool update memory.rrd "N:$_ACTIVE:$_INACTIVE:$_MEMFREE"
}

graph() {
    rrdtool graph memory.png -a PNG --title="MemoryUsage" \
        --vertical-label "KB" \
        'DEF:active=memory.rrd:active:AVERAGE' \
        'DEF:inactive=memory.rrd:inactive:AVERAGE' \
        'DEF:free=memory.rrd:free:AVERAGE' \
        'LINE1:active#ff0000:Active Usage' \
        'LINE1:inactive#0400ff:Inactive Usage' \
        'LINE1:free#0700ff:Free'
}

update_interval() {
    update
    _TIMES=${1:-300}
    sleep $_TIMES
}

update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1
update_interval 1

graph