location /nginx_status {
        stub_status on;
        access_log   off;
        allow 127.0.0.1;
        deny all;
        }
#!/bin/bash

rrdtool=/usr/bin/rrdtool
db1=~/rrd/db/cpu.rrd
db2=~/rrd/db/memory.rrd
db3=~/rrd/db/network.rrd
db4=~/rrd/db/requests.rrd
img=graph
if=eth0
url=http://127.0.0.1/nginx_status

if [ ! -e $db1 ]
then   
        $rrdtool create $db1 --step 15\
        DS:user:COUNTER:30:0:100 \
        DS:nice:COUNTER:30:0:100 \
        DS:system:COUNTER:30:0:100 \
        DS:idle:COUNTER:30:0:100 \
        RRA:AVERAGE:0.5:1:576 \
        RRA:AVERAGE:0.5:6:672 \
        RRA:AVERAGE:0.5:24:732 \
        RRA:AVERAGE:0.5:144:1460
fi
if [ ! -e $db2 ]
then   
        $rrdtool create $db2 --step 15\
        DS:used:GAUGE:30:0:U \
        DS:free:GAUGE:30:0:U \
        DS:buffer:GAUGE:30:0:U \
        DS:cached:GAUGE:30:0:U \
        DS:swap:GAUGE:30:0:U \
        RRA:AVERAGE:0.5:1:576 \
        RRA:AVERAGE:0.5:6:672 \
        RRA:AVERAGE:0.5:24:732 \
        RRA:AVERAGE:0.5:144:1460
fi
if [ ! -e $db3 ]
then   
        $rrdtool create $db3 --step 15\
        DS:in:DERIVE:30:0:12500000 \
        DS:out:DERIVE:30:0:12500000 \
        RRA:AVERAGE:0.5:1:576 \
        RRA:AVERAGE:0.5:6:672 \
        RRA:AVERAGE:0.5:24:732 \
        RRA:AVERAGE:0.5:144:1460
fi
if [ ! -e $db4 ]
then   
        $rrdtool create $db4 --step 15\
        DS:requests:DERIVE:30:0:50000000000 \
        RRA:AVERAGE:0.5:1:576 \
        RRA:AVERAGE:0.5:6:672 \
        RRA:AVERAGE:0.5:24:732 \
        RRA:AVERAGE:0.5:144:1460
fi


cpu=(`cat /proc/stat | grep '^cpu '`)
$rrdtool update $db1 -t user:nice:system:idle N:${cpu[1]}:${cpu[2]}:${cpu[3]}:${cpu[4]}
output=`awk '
    /^MemTotal:/    {total=$2*1024}
    /^MemFree:/     {free=$2*1024}
    /^Buffers:/     {buffer=$2*1024}
    /^Cached:/      {cached=$2*1024}
    /^SwapTotal:/   {swaptotal=$2*1024}
    /^SwapFree:/    {swapfree=$2*1024}
    END {
        used=total-free
        swap=swaptotal-swapfree
        print used ":" free ":" buffer ":" cached ":" swap
    }' /proc/meminfo`
$rrdtool update $db2 -t used:free:buffer:cached:swap N:$output
$rrdtool update $db3 -t in:out N:`/sbin/ifconfig $if |grep bytes|cut -d":" -f2|cut -d" " -f1`:`/sbin/ifconfig $if |grep bytes|cut -d":" -f3|cut -d" " -f1`
$rrdtool update $db4 -t requests N:`wget -qO- $url |head -3|tail -1|cut -d' ' -f4`