#!/bin/bash # info: update memory rrd # options: period # # The function is for updating memory rrd database and graphic. #----------------------------------------------------------# # Variable&Function # #----------------------------------------------------------# # Argument defenition update=$1 period=${1-daily} # Importing variables source $VESTA/conf/vars.conf #----------------------------------------------------------# # Action # #----------------------------------------------------------# # Switching on time period case $period in daily) start='-1d'; end='now'; grid='MINUTE:30:HOUR:1:HOUR:4:0:%H:%M';; weekly) start='-7d'; end='now'; grid='HOUR:8:DAY:1:DAY:1:0:%a %d';; monthly) start='-1m'; end='now'; grid='WEEK:1:WEEK:1:WEEK:1:0:%b %d';; yearly) start='-1y'; end='now'; grid='MONTH:1:YEAR:1:MONTH:2:2419200:%b';; *) exit $E_RRD ;; esac # Checking directory if [ ! -d "$V_RRD/mem" ]; then mkdir $V_RRD/mem fi # Checking database if [ ! -e "$V_RRD/mem/mem.rrd" ]; then # Adding database rrdtool create $V_RRD/mem/mem.rrd --step $V_RRD_STEP \ DS:RAM:GAUGE:600:U:U \ DS:SWAP:GAUGE:600:U:U \ RRA:AVERAGE:0.5:1:600 \ RRA:AVERAGE:0.5:6:700 \ RRA:AVERAGE:0.5:24:775 \ RRA:AVERAGE:0.5:288:797 \ RRA:MAX:0.5:1:600 \ RRA:MAX:0.5:6:700 \ RRA:MAX:0.5:24:775 \ RRA:MAX:0.5:288:797 fi # Parsing data if [ -z "$update" ]; then mem=$(free -m) ram=$(echo "$mem" |awk '{print $3}'|head -n2 |tail -n1) swap=$(echo "$mem" |awk '{print $3}'|tail -n1) # Updating rrd rrdtool update $V_RRD/mem/mem.rrd N:$ram:$swap fi # Updating rrd graph rrdtool graph $V_RRD/mem/$period-mem.png \ --imgformat PNG \ --height="120" \ --width="440" \ --start "$start" \ --end "$end" \ --vertical-label "Mbytes" \ --x-grid "$grid" \ -c "BACK#484439" \ -c "SHADEA#484439" \ -c "SHADEB#484439" \ -c "FONT#DDDDDD" \ -c "CANVAS#202020" \ -c "GRID#666666" \ -c "MGRID#AAAAAA" \ -c "FRAME#202020" \ -c "ARROW#FFFFFF" \ DEF:ram=$V_RRD/mem/mem.rrd:RAM:AVERAGE \ DEF:swap=$V_RRD/mem/mem.rrd:SWAP:AVERAGE \ COMMENT:'\r' \ AREA:ram#867995:"RAM "\ GPRINT:ram:'LAST: Current\:''%8.0lf' \ GPRINT:ram:'MIN: Min\:''%8.0lf' \ GPRINT:ram:'MAX: Max\:''%8.0lf\j' \ LINE1:swap#f57900:"SWAP" \ GPRINT:swap:'LAST:Current\:''%8.0lf' \ GPRINT:swap:'MIN:Min\:''%8.0lf' \ GPRINT:swap:'MAX:Max\:''%8.0lf\j' >/dev/null 2> /dev/null; result=$? #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# if [ "$result" -ne 0 ]; then exit $E_RRD fi exit