Implement trigger functions show_variables and show_status.

This commit is contained in:
Daniel Nichter
2011-11-02 16:05:59 -06:00
parent a0a0590cd1
commit 1e04b40869

View File

@@ -77,6 +77,9 @@ MB_THRESHOLD=${MB_THRESHOLD:-100}
# Remove samples after this many days.
PURGE=${PURGE:-30}
# Which trigger function to call to get the value of VARIABLE.
TRIGGER_FUNCTION=${TRIGGER_FUNCTION:-"show_status"}
# ########################################################################
# End configuration
# ########################################################################
@@ -89,6 +92,19 @@ die() {
exit 1
}
# ########################################################################
# Trigger functions
# ########################################################################
show_status() {
local var=$1
mysqladmin ${MYSQLOPTIONS} extended-status | grep ${VARIABLE} | awk '{print $4}'
}
show_variables() {
local var=$1
mysqladmin ${MYSQLOPTIONS} variables | grep ${VARIABLE} | awk '{print $4}'
}
# ########################################################################
# Echo to STDERR and possibly email.
# ########################################################################
@@ -119,11 +135,11 @@ main() {
while true; do
d=$(date +%F-%T | tr :- _);
# XXX This is where we decide whether to execute 'collect'.
# XXX Customize this if needed. The idea is to generate a number and store
# XXX it into $detected, and if $detected > $THRESHOLD, then we'll execute
# XXX the collection process.
detected=$(mysqladmin ext ${MYSQLOPTIONS} | grep ${VARIABLE} | awk '{print $4}');
# This is where we decide whether to execute 'collect'.
# The idea is to generate a number and store into $detected,
# and if $detected > $THRESHOLD, then we'll execute pt-collect.
local detected=$($TRIGGER_FUNCTION $VARIABLE)
if [ -z "${detected}" -a ${MAYBE_EMPTY} = "no" ]; then
# Oops, couldn't connect, maybe max_connections problem?
echo "$d The detected value is empty; something failed? Exit status is $?"
@@ -137,8 +153,6 @@ main() {
cycles_true=0
fi
# XXX Stop customizing here; everything above should be what you need.
NOTE="$d check results: ${VARIABLE} = ${detected}, matched = ${matched}, cycles_true = ${cycles_true}"
# Actually execute the collection script.
if [ "${matched:-no}" = "yes" -a ${cycles_true} -ge ${CYCLES} ]; then
@@ -154,7 +168,6 @@ main() {
sleep ${INTERVAL}
fi
# Delete things more than $PURGE days old
find "${DEST}" -type f -mtime +${PURGE} -exec rm -f '{}' \;
find "/var/lib/oprofile/samples" -type d -name 'pt_collect_*' \
@@ -273,6 +286,11 @@ This is the max number of <whatever> we want to tolerate.
This is the thing to check for.
=item TRIGGER_FUNCTION (default show_status)
Built-in function name to get the value of VARIABLE, either C<show_status>
or C<show_variables>.
=item CYCLES (default 1)
How many times must the condition be met before the script will fire?