summaryrefslogtreecommitdiffstats
path: root/adei/check_adei.sh
diff options
context:
space:
mode:
Diffstat (limited to 'adei/check_adei.sh')
-rwxr-xr-xadei/check_adei.sh97
1 files changed, 97 insertions, 0 deletions
diff --git a/adei/check_adei.sh b/adei/check_adei.sh
new file mode 100755
index 0000000..58ce49c
--- /dev/null
+++ b/adei/check_adei.sh
@@ -0,0 +1,97 @@
+#! /bin/bash
+
+. $(dirname "$0")/lib/adei/adei.sh
+
+adei_init "$@"; code=$?
+
+online=${adei_online}
+healthy=$(( $code == 0 ))
+
+adei_version_check "0.0.10"
+[ $? -eq 0 ] && adei10=1
+
+msg=""
+[ -n "$adei_version" ] && msg+="ADEI $adei_version"
+
+# Get current database size
+[ -n "$adei10" ] && size=$(adei_text_query "info.php?target=size&encoding=text")
+
+[[ "$size" =~ "Error:" ]] && size=""
+[ -n "$size" ] && msg+=" \${color gray}/ $((size / 1024 / 1024 / 1024)) GB"
+
+# Check pending administrative scripts
+if [ -n "$adei10" -a $healthy -ne 0 ]; then
+ scripts=$(adei_xml_query "info.php?target=scripts"); err=$?
+ [ $err -eq 0 ] && waiting="$(echo $scripts | grep "Value" | sed -e "s/^\(.*mtime=\"\([^\"]*\)\".*\)$/\\2\\1/" | awk -v date="$(date +%s)" '{duration=date - $1} duration > 3600 { print duration }' | sort -rn)" #"
+
+ if [ $err -ne 0 ]; then
+ adei_print_error $err "ScriptInfo" "$waiting"
+ healthy=0
+ elif [ -n "$waiting" ]; then
+ num_waiting="$(echo $waiting | tr ' ' '\n' | wc -l)"
+ long_waiting="$(echo $waiting | cut -d ' ' -f 1)"
+ if [ $num_waiting -gt 0 ]; then
+ healthy=2
+ echo "$num_waiting pending scripts, longest for $(format_time $long_waiting)"
+ fi
+ fi
+fi
+
+# Verify offset (for selected database)
+if [ -n "$adei10" -a $healthy -ne 0 -a -n "$adei_source" ]; then
+ now=$(date +%s)
+ sdate="$(adei_text_query "getdata.php?db_mask=0&format=csv&window=-1&rt=1&cache=1&time_format=U&mysql=slave")"; err_slave=$?
+ [ $err_slave -eq 0 ] && sdate="$(echo "$sdate" | cut -d ',' -f 1 | cut -d '.' -f 1)"
+ mdate="$(adei_text_query "getdata.php?db_mask=0&format=csv&window=-1&rt=1&cache=1&time_format=U&mysql=master")"; err_master=$?
+ [ $err_master -eq 0 ] && mdate="$(echo "$mdate" | cut -d ',' -f 1 | cut -d '.' -f 1)"
+
+ src="$adei_source"
+ if [ $err_slave -ne 0 -o $err_master -ne 0 -o -z "$sdate" -o -z "$mdate" ]; then
+
+ echo -n "Error querying (${err_master:+master} ${err_slave:+slave}) data from cache of '$src': "
+ if [ $err_master -ne 0 ]; then
+ echo "$(adei_print_error $err_master "$mdate")"
+ elif [ $err_slave -ne 0 ]; then
+ echo "$(adei_print_error $err_slave "$sdate")"
+ else
+ echo "Unexpected response from getdata service"
+ fi
+ healthy=0
+ else
+ master_offset=$(($now - $mdate))
+ slave_offset=$(($mdate - $sdate))
+
+ if [ $master_offset -gt $MAX_SOURCE_OFFSET ]; then
+ rdate=$(adei_text_query "getdata.php?db_mask=0&format=csv&window=-1&rt=1&time_format=U&mysql=master"); err=$?
+ if [ $err -eq 0 ]; then
+ rdate="$(echo "$rdate" | cut -d ',' -f 1 | cut -d '.' -f 1)"
+ cache_offset=$(($rdate - $mdate))
+
+ if [ $cache_offset -gt $MAX_MASTER_OFFSET ]; then
+ echo "ADEI cache is off by $(format_time $cache_offset) for '$src'"
+ healthy=2
+ else
+ offset=$(($now - $rdate))
+# echo "Source '$src' is not updated for $(format_time $offset)"
+ fi
+ else
+ echo -n "Error querying data from '$src' primary database: "
+ echo "$(adei_print_error $err_master "$rdate")"
+ healthy=0
+ fi
+ fi
+
+ if [ $slave_offset -gt $MAX_SLAVE_OFFSET ]; then
+ echo "MySQL slave is off by $(format_time $slave_offset) for '$src'"
+ healthy=2
+ fi
+
+ [ -n "$msg" ] && msg="${msg}, "
+ [ -z "$msg" ] && msg="\${color gray}/ "
+ msg="${msg}cache $(format_time $master_offset)"
+ [ $slave_offset -gt 0 ] && msg="$msg & slave $(format_time $slave_offset)"
+ msg="$msg off"
+ fi
+fi
+
+echo "$(adei_print_status "$0" $online $healthy) $msg"