myvesta/bin/v-update-sys-rrd-la
2023-06-04 17:56:44 +02:00

104 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
# info: update load average rrd
# options: PERIOD
#
# The function is for updating load average rrd database and graphic.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
period=${1-daily}
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.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 "$RRD/la" ]; then
mkdir $RRD/la
fi
# Checking database
if [ ! -e "$RRD/la/la.rrd" ]; then
# Adding database
rrdtool create $RRD/la/la.rrd --step $RRD_STEP \
DS:LA:GAUGE:600:U:U \
DS:PR: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 [ "$period" = 'daily' ]; then
loadavg=$(cat /proc/loadavg )
la=$(echo "$loadavg"|cut -f 2 -d ' ')
pr=$(ps auxh |wc -l)
# Updating rrd database
rrdtool update $RRD/la/la.rrd N:${la//./}:$pr
fi
# Updating graph
rrdtool graph $RRD/la/$period-la.png \
--imgformat PNG \
--height="350" \
--width="670" \
--start "$start" \
--end "$end" \
--vertical-label "Points" \
--x-grid "$grid" \
-c "BACK#ffffff" \
-c "SHADEA#ffffff" \
-c "SHADEB#ffffff" \
-c "FONT#555555" \
-c "CANVAS#F2F2F2" \
-c "GRID#666666" \
-c "MGRID#AAAAAA" \
-c "FRAME#777777" \
-c "ARROW#555555" \
DEF:la=$RRD/la/la.rrd:LA:AVERAGE \
DEF:pr=$RRD/la/la.rrd:PR:AVERAGE \
COMMENT:'\r' \
AREA:la#00CD2E:"LA * 100"\
GPRINT:la:'LAST: Current\:''%8.0lf' \
GPRINT:la:'MIN: Min\:''%8.0lf' \
GPRINT:la:'MAX: Max\:''%8.0lf\j' \
LINE1:pr#1c74cd:"Procs # " \
GPRINT:pr:'LAST:Current\:''%8.0lf' \
GPRINT:pr:'MIN:Min\:''%8.0lf' \
GPRINT:pr:'MAX:Max\:''%8.0lf\j' &>/dev/null; result=$?
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
if [ "$result" -ne 0 ]; then
exit $E_RRD
fi
exit