mirror of
https://github.com/myvesta/vesta
synced 2025-08-14 10:37:42 -07:00
renamed api function per naming convention
This commit is contained in:
parent
f7d1d2c84e
commit
94ddaa3622
84 changed files with 40 additions and 40 deletions
139
bin/v_update_sys_rrd_mysql
Executable file
139
bin/v_update_sys_rrd_mysql
Executable file
|
@ -0,0 +1,139 @@
|
|||
#!/bin/bash
|
||||
# info: updating MySQL rrd
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
update=$1
|
||||
period=${1-daily}
|
||||
|
||||
# Importing variables
|
||||
source $VESTA/conf/vars.conf
|
||||
source $V_FUNC/shared.func
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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/db" ]; then
|
||||
mkdir $V_RRD/db
|
||||
fi
|
||||
|
||||
# Parsing db hosts
|
||||
conf="$V_DB/mysql.conf"
|
||||
fields='$HOST'
|
||||
nohead=1
|
||||
hosts=$(shell_list)
|
||||
check_row=$(echo "$hosts" |wc -l)
|
||||
if [ 0 -eq "$check_row" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Parsing excludes
|
||||
for exclude in $(echo ${V_RRD_MYSQL_EXCLUDE//,/ }); do
|
||||
hosts=$(echo "$hosts" |grep -vw "$exclude" )
|
||||
done
|
||||
|
||||
for host in $hosts; do
|
||||
# Checking database
|
||||
if [ ! -e "$V_RRD/db/mysql_$host.rrd" ]; then
|
||||
# Adding database
|
||||
rrdtool create $V_RRD/db/mysql_$host.rrd --step $V_RRD_STEP \
|
||||
DS:A:COUNTER:600:U:U \
|
||||
DS:S:COUNTER: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
|
||||
|
||||
if [ -z "$update" ]; then
|
||||
# Defining host credentials
|
||||
host_str=$(grep "HOST='$host'" $conf)
|
||||
for key in $host_str; do
|
||||
eval ${key%%=*}=${key#*=}
|
||||
done
|
||||
sql="mysql -h $HOST -u $USER -p$PASSWORD -P$PORT -e"
|
||||
|
||||
# Checking empty vars
|
||||
if [ -z $HOST ] || [ -z $USER ] || [ -z $PASSWORD ] || [ -z $PORT ]
|
||||
then
|
||||
echo "Error: config is broken"
|
||||
log_event 'debug' "$E_PARSING $V_EVENT"
|
||||
exit $E_PARSING
|
||||
fi
|
||||
|
||||
# Parsing data
|
||||
status=$($sql "SHOW GLOBAL STATUS" 2>/dev/null); code="$?"
|
||||
if [ '0' -ne "$code" ]; then
|
||||
active=0
|
||||
slow=0
|
||||
else
|
||||
active=$(echo "$status"|grep 'Queries'|cut -f 2)
|
||||
slow=$(echo "$status"|grep 'Slow_queries'|cut -f 2)
|
||||
fi
|
||||
|
||||
# Updating rrd
|
||||
rrdtool update $V_RRD/db/mysql_$host.rrd N:$active:$slow
|
||||
fi
|
||||
|
||||
# Updating daily graph
|
||||
rrdtool graph $V_RRD/db/$period-mysql_$host.png \
|
||||
--imgformat PNG \
|
||||
--height="120" \
|
||||
--width="440" \
|
||||
--start "$start" \
|
||||
--end "$end" \
|
||||
--title "MySQL Usage on $host ($period)" \
|
||||
--vertical-label "Queries" \
|
||||
--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:a=$V_RRD/db/mysql_$host.rrd:A:AVERAGE \
|
||||
DEF:s=$V_RRD/db/mysql_$host.rrd:S:AVERAGE \
|
||||
COMMENT:'\r' \
|
||||
LINE1:a#fefda0:"Queries"\
|
||||
GPRINT:a:'LAST: Current\:''%8.0lf' \
|
||||
GPRINT:a:'MIN: Min\:''%8.0lf' \
|
||||
GPRINT:a:'MAX: Max\:''%8.0lf\j' \
|
||||
AREA:s#f57900:"Slow " \
|
||||
GPRINT:s:'LAST:Current\:''%8.0lf' \
|
||||
GPRINT:s:'MIN:Min\:''%8.0lf' \
|
||||
GPRINT:s:'MAX:Max\:''%8.0lf\j' >/dev/null 2>/dev/null; result=$?
|
||||
|
||||
if [ "$result" -ne 0 ]; then
|
||||
exit $E_RRD
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
exit
|
Loading…
Add table
Add a link
Reference in a new issue