mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-22 19:04:30 +00:00
Merge pt-stalk-quiet.
This commit is contained in:
@@ -20,23 +20,32 @@ PTFUNCNAME=""
|
|||||||
PTDEBUG="${PTDEBUG:-""}"
|
PTDEBUG="${PTDEBUG:-""}"
|
||||||
EXIT_STATUS=0
|
EXIT_STATUS=0
|
||||||
|
|
||||||
log() {
|
ts() {
|
||||||
TS=$(date +%F-%T | tr ':-' '_');
|
TS=$(date +%F-%T | tr ':-' '_')
|
||||||
echo "$TS $*"
|
echo "$TS $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
log "$*" >&2
|
[ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
|
||||||
EXIT_STATUS=1
|
EXIT_STATUS=1
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
warn "$*"
|
ts "$*" >&2
|
||||||
|
EXIT_STATUS=1
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
_d () {
|
_d () {
|
||||||
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2
|
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
@@ -861,7 +870,7 @@ main() {
|
|||||||
# Execute the program if it was not included from another file.
|
# Execute the program if it was not included from another file.
|
||||||
# This makes it possible to include without executing, and thus test.
|
# This makes it possible to include without executing, and thus test.
|
||||||
if [ "${0##*/}" = "$TOOL" ] \
|
if [ "${0##*/}" = "$TOOL" ] \
|
||||||
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
|
|| [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
|
||||||
|
|
||||||
# Parse command line options. We must do this first so we can
|
# Parse command line options. We must do this first so we can
|
||||||
# see if --daemonize was specified.
|
# see if --daemonize was specified.
|
||||||
|
@@ -22,23 +22,32 @@ PTFUNCNAME=""
|
|||||||
PTDEBUG="${PTDEBUG:-""}"
|
PTDEBUG="${PTDEBUG:-""}"
|
||||||
EXIT_STATUS=0
|
EXIT_STATUS=0
|
||||||
|
|
||||||
log() {
|
ts() {
|
||||||
TS=$(date +%F-%T | tr ':-' '_');
|
TS=$(date +%F-%T | tr ':-' '_')
|
||||||
echo "$TS $*"
|
echo "$TS $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
log "$*" >&2
|
[ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
|
||||||
EXIT_STATUS=1
|
EXIT_STATUS=1
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
warn "$*"
|
ts "$*" >&2
|
||||||
|
EXIT_STATUS=1
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
_d () {
|
_d () {
|
||||||
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2
|
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
@@ -2412,7 +2421,7 @@ main() {
|
|||||||
# Execute the program if it was not included from another file.
|
# Execute the program if it was not included from another file.
|
||||||
# This makes it possible to include without executing, and thus test.
|
# This makes it possible to include without executing, and thus test.
|
||||||
if [ "${0##*/}" = "$TOOL" ] \
|
if [ "${0##*/}" = "$TOOL" ] \
|
||||||
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
|
|| [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
|
||||||
|
|
||||||
# Set up temporary dir.
|
# Set up temporary dir.
|
||||||
mk_tmpdir
|
mk_tmpdir
|
||||||
|
@@ -215,7 +215,7 @@ main() {
|
|||||||
# Execute the program if it was not included from another file. This makes it
|
# Execute the program if it was not included from another file. This makes it
|
||||||
# possible to include without executing, and thus test.
|
# possible to include without executing, and thus test.
|
||||||
if [ "${0##*/}" = "$TOOL" ] \
|
if [ "${0##*/}" = "$TOOL" ] \
|
||||||
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
|
|| [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
|
||||||
mk_tmpdir
|
mk_tmpdir
|
||||||
main "$@"
|
main "$@"
|
||||||
rm_tmpdir
|
rm_tmpdir
|
||||||
|
@@ -587,7 +587,7 @@ main() {
|
|||||||
# Execute the program if it was not included from another file. This makes it
|
# Execute the program if it was not included from another file. This makes it
|
||||||
# possible to include without executing, and thus test.
|
# possible to include without executing, and thus test.
|
||||||
if [ "${0##*/}" = "$TOOL" ] \
|
if [ "${0##*/}" = "$TOOL" ] \
|
||||||
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
|
|| [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
|
||||||
main "${@:-""}"
|
main "${@:-""}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
67
bin/pt-stalk
67
bin/pt-stalk
@@ -22,23 +22,32 @@ PTFUNCNAME=""
|
|||||||
PTDEBUG="${PTDEBUG:-""}"
|
PTDEBUG="${PTDEBUG:-""}"
|
||||||
EXIT_STATUS=0
|
EXIT_STATUS=0
|
||||||
|
|
||||||
log() {
|
ts() {
|
||||||
TS=$(date +%F-%T | tr ':-' '_');
|
TS=$(date +%F-%T | tr ':-' '_')
|
||||||
echo "$TS $*"
|
echo "$TS $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
log "$*" >&2
|
[ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
|
||||||
EXIT_STATUS=1
|
EXIT_STATUS=1
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
warn "$*"
|
ts "$*" >&2
|
||||||
|
EXIT_STATUS=1
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
_d () {
|
_d () {
|
||||||
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2
|
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
@@ -962,6 +971,10 @@ after_collect_sleep() {
|
|||||||
:
|
:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
after_interval_sleep() {
|
||||||
|
:
|
||||||
|
}
|
||||||
|
|
||||||
after_stalk() {
|
after_stalk() {
|
||||||
:
|
:
|
||||||
}
|
}
|
||||||
@@ -1066,9 +1079,7 @@ sleep_ok() {
|
|||||||
local seconds="$1"
|
local seconds="$1"
|
||||||
local msg="${2:-""}"
|
local msg="${2:-""}"
|
||||||
if oktorun; then
|
if oktorun; then
|
||||||
if [ -n "$msg" ]; then
|
[ "$msg" ] && info "$msg"
|
||||||
log "$msg"
|
|
||||||
fi
|
|
||||||
sleep $seconds
|
sleep $seconds
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -1126,7 +1137,11 @@ stalk() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local msg="Check results: $OPT_VARIABLE=$value, matched=${matched:-no}, cycles_true=$cycles_true"
|
local msg="Check results: $OPT_VARIABLE=$value, matched=${matched:-no}, cycles_true=$cycles_true"
|
||||||
log "$msg"
|
if [ "$matched" ]; then
|
||||||
|
log "$msg"
|
||||||
|
else
|
||||||
|
info "$msg"
|
||||||
|
fi
|
||||||
elif [ "$OPT_COLLECT" ]; then
|
elif [ "$OPT_COLLECT" ]; then
|
||||||
# Make the next if condition true.
|
# Make the next if condition true.
|
||||||
matched=1
|
matched=1
|
||||||
@@ -1140,7 +1155,7 @@ stalk() {
|
|||||||
# ##################################################################
|
# ##################################################################
|
||||||
# Start collecting, maybe.
|
# Start collecting, maybe.
|
||||||
# ##################################################################
|
# ##################################################################
|
||||||
log "Collect triggered"
|
log "Collect $ITER triggered"
|
||||||
|
|
||||||
# Send email to whomever that collect has been triggered.
|
# Send email to whomever that collect has been triggered.
|
||||||
if [ "$OPT_NOTIFY_BY_EMAIL" ]; then
|
if [ "$OPT_NOTIFY_BY_EMAIL" ]; then
|
||||||
@@ -1166,8 +1181,8 @@ stalk() {
|
|||||||
"$margin"
|
"$margin"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
# There should be enough disk space, so collect.
|
# There should be enough disk space, so collect.
|
||||||
log "$msg" >> "$OPT_DEST/$prefix-trigger"
|
ts "$msg" >> "$OPT_DEST/$prefix-trigger"
|
||||||
log "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger"
|
ts "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger"
|
||||||
last_prefix="$prefix"
|
last_prefix="$prefix"
|
||||||
|
|
||||||
# Plugin hook:
|
# Plugin hook:
|
||||||
@@ -1181,7 +1196,7 @@ stalk() {
|
|||||||
collect "$OPT_DEST" "$prefix"
|
collect "$OPT_DEST" "$prefix"
|
||||||
) >> "$OPT_DEST/$prefix-output" 2>&1 &
|
) >> "$OPT_DEST/$prefix-output" 2>&1 &
|
||||||
local collector_pid=$!
|
local collector_pid=$!
|
||||||
log "Collector PID $collector_pid"
|
log "Collect $ITER PID $collector_pid"
|
||||||
|
|
||||||
# Plugin hook:
|
# Plugin hook:
|
||||||
after_collect $collector_pid
|
after_collect $collector_pid
|
||||||
@@ -1199,6 +1214,7 @@ stalk() {
|
|||||||
# ##################################################################
|
# ##################################################################
|
||||||
# Done collecting.
|
# Done collecting.
|
||||||
# ##################################################################
|
# ##################################################################
|
||||||
|
log "Collect $ITER done"
|
||||||
ITER=$((ITER + 1))
|
ITER=$((ITER + 1))
|
||||||
cycles_true=0
|
cycles_true=0
|
||||||
sleep_ok "$OPT_SLEEP" "Sleeping $OPT_SLEEP seconds after collect"
|
sleep_ok "$OPT_SLEEP" "Sleeping $OPT_SLEEP seconds after collect"
|
||||||
@@ -1208,6 +1224,9 @@ stalk() {
|
|||||||
else
|
else
|
||||||
# Trigger/check/value is ok, sleep until next check.
|
# Trigger/check/value is ok, sleep until next check.
|
||||||
sleep_ok "$OPT_INTERVAL"
|
sleep_ok "$OPT_INTERVAL"
|
||||||
|
|
||||||
|
# Plugin hook:
|
||||||
|
after_interval_sleep
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -1291,7 +1310,7 @@ main() {
|
|||||||
# Execute the program if it was not included from another file.
|
# Execute the program if it was not included from another file.
|
||||||
# This makes it possible to include without executing, and thus test.
|
# This makes it possible to include without executing, and thus test.
|
||||||
if [ "${0##*/}" = "$TOOL" ] \
|
if [ "${0##*/}" = "$TOOL" ] \
|
||||||
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
|
|| [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
|
||||||
|
|
||||||
# Parse command line options. We must do this first so we can
|
# Parse command line options. We must do this first so we can
|
||||||
# see if --daemonize was specified.
|
# see if --daemonize was specified.
|
||||||
@@ -1737,6 +1756,10 @@ C<after_collect_sleep>.
|
|||||||
Called after sleeping L<"--sleep"> seconds for the collector process to finish.
|
Called after sleeping L<"--sleep"> seconds for the collector process to finish.
|
||||||
This hook is called after C<after_collect>.
|
This hook is called after C<after_collect>.
|
||||||
|
|
||||||
|
=item after_interval_sleep
|
||||||
|
|
||||||
|
Called after sleeping L<"--interval"> seconds after each trigger check.
|
||||||
|
|
||||||
=item after_stalk
|
=item after_stalk
|
||||||
|
|
||||||
Called after stalking. Since pt-stalk stalks forever by default,
|
Called after stalking. Since pt-stalk stalks forever by default,
|
||||||
@@ -1840,6 +1863,22 @@ type: string; default: Threads_running
|
|||||||
|
|
||||||
The variable to compare against the threshold. See L<"--function"> for details.
|
The variable to compare against the threshold. See L<"--function"> for details.
|
||||||
|
|
||||||
|
=item --verbose
|
||||||
|
|
||||||
|
type: int; default: 2
|
||||||
|
|
||||||
|
Print more or less information while running. Since the tool is designed
|
||||||
|
to be a long-running daemon, the default verbosity level only prints the
|
||||||
|
most important information. If you run the tool interactively, you may
|
||||||
|
want to use a higher verbosity level.
|
||||||
|
|
||||||
|
LEVEL PRINTS
|
||||||
|
===== =====================================
|
||||||
|
0 Errors
|
||||||
|
1 Warnings
|
||||||
|
2 Matching triggers and collection info
|
||||||
|
3 Non-matching triggers
|
||||||
|
|
||||||
=item --version
|
=item --version
|
||||||
|
|
||||||
Print tool's version and exit.
|
Print tool's version and exit.
|
||||||
|
@@ -29,23 +29,32 @@ PTFUNCNAME=""
|
|||||||
PTDEBUG="${PTDEBUG:-""}"
|
PTDEBUG="${PTDEBUG:-""}"
|
||||||
EXIT_STATUS=0
|
EXIT_STATUS=0
|
||||||
|
|
||||||
log() {
|
ts() {
|
||||||
TS=$(date +%F-%T | tr ':-' '_');
|
TS=$(date +%F-%T | tr ':-' '_')
|
||||||
echo "$TS $*"
|
echo "$TS $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
log "$*" >&2
|
[ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
|
||||||
EXIT_STATUS=1
|
EXIT_STATUS=1
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
warn "$*"
|
ts "$*" >&2
|
||||||
|
EXIT_STATUS=1
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
_d () {
|
_d () {
|
||||||
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2
|
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
@@ -2280,7 +2289,7 @@ sigtrap() { local PTFUNCNAME=sigtrap;
|
|||||||
# Execute the program if it was not included from another file. This makes it
|
# Execute the program if it was not included from another file. This makes it
|
||||||
# possible to include without executing, and thus test.
|
# possible to include without executing, and thus test.
|
||||||
if [ "${0##*/}" = "$TOOL" ] \
|
if [ "${0##*/}" = "$TOOL" ] \
|
||||||
|| [ "${0##*/}" = "bash" -a "$_" = "$0" ]; then
|
|| [ "${0##*/}" = "bash" -a "${_:-""}" = "$0" ]; then
|
||||||
|
|
||||||
# Set up temporary dir.
|
# Set up temporary dir.
|
||||||
mk_tmpdir
|
mk_tmpdir
|
||||||
|
@@ -58,7 +58,6 @@ our @EXPORT = qw(
|
|||||||
wait_until
|
wait_until
|
||||||
wait_for
|
wait_for
|
||||||
wait_until_slave_running
|
wait_until_slave_running
|
||||||
wait_until_no_lag
|
|
||||||
test_log_parser
|
test_log_parser
|
||||||
test_protocol_parser
|
test_protocol_parser
|
||||||
test_packet_parser
|
test_packet_parser
|
||||||
@@ -325,6 +324,39 @@ sub wait_for_sh {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sub kill_program {
|
||||||
|
my (%args) = @_;
|
||||||
|
|
||||||
|
my $pid_file = $args{pid_file};
|
||||||
|
my $pid = $args{pid};
|
||||||
|
|
||||||
|
if ( $pid_file ) {
|
||||||
|
chomp($pid = `cat $pid_file 2>/dev/null`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $pid ) {
|
||||||
|
PTDEVDEBUG && _d('Killing PID', $pid);
|
||||||
|
kill(15, $pid);
|
||||||
|
wait_until(
|
||||||
|
sub { my $is_alive = kill(0, $pid); return !$is_alive; },
|
||||||
|
1.5, # sleep between tries
|
||||||
|
15, # max time to try
|
||||||
|
);
|
||||||
|
if ( kill(0, $pid) ) {
|
||||||
|
warn "PID $pid did not die; using kill -9\n";
|
||||||
|
kill(9, $pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PTDEVDEBUG && _d('No PID to kill');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $pid_file && -f $pid_file ) {
|
||||||
|
PTDEVDEBUG && _d('Removing PID file', $pid_file);
|
||||||
|
unlink $pid_file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub not_running {
|
sub not_running {
|
||||||
my ($cmd) = @_;
|
my ($cmd) = @_;
|
||||||
PTDEVDEBUG && _d('Wait until not running:', $cmd);
|
PTDEVDEBUG && _d('Wait until not running:', $cmd);
|
||||||
|
@@ -28,23 +28,32 @@ PTFUNCNAME=""
|
|||||||
PTDEBUG="${PTDEBUG:-""}"
|
PTDEBUG="${PTDEBUG:-""}"
|
||||||
EXIT_STATUS=0
|
EXIT_STATUS=0
|
||||||
|
|
||||||
log() {
|
ts() {
|
||||||
TS=$(date +%F-%T | tr ':-' '_');
|
TS=$(date +%F-%T | tr ':-' '_')
|
||||||
echo "$TS $*"
|
echo "$TS $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 3 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
[ ${OPT_VERBOSE:-3} -ge 2 ] && ts "$*"
|
||||||
|
}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
log "$*" >&2
|
[ ${OPT_VERBOSE:-3} -ge 1 ] && ts "$*" >&2
|
||||||
EXIT_STATUS=1
|
EXIT_STATUS=1
|
||||||
}
|
}
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
warn "$*"
|
ts "$*" >&2
|
||||||
|
EXIT_STATUS=1
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
_d () {
|
_d () {
|
||||||
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2
|
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(ts "$*")" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
|
@@ -1,17 +1,15 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
plan 6
|
|
||||||
|
|
||||||
source "$LIB_DIR/log_warn_die.sh"
|
source "$LIB_DIR/log_warn_die.sh"
|
||||||
|
|
||||||
log "Hello world!" > $TEST_PT_TMPDIR/log
|
log "Hello world A!" > $TEST_PT_TMPDIR/log
|
||||||
cmd_ok \
|
cmd_ok \
|
||||||
"grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \
|
"grep -q 'Hello world A!' $TEST_PT_TMPDIR/log" \
|
||||||
"log msg"
|
"log msg"
|
||||||
|
|
||||||
log "Hello" "world!" > $TEST_PT_TMPDIR/log
|
log "Hello" "world B!" > $TEST_PT_TMPDIR/log
|
||||||
cmd_ok \
|
cmd_ok \
|
||||||
"grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \
|
"grep -q 'Hello world B!' $TEST_PT_TMPDIR/log" \
|
||||||
"log msg msg"
|
"log msg msg"
|
||||||
|
|
||||||
is \
|
is \
|
||||||
@@ -19,14 +17,14 @@ is \
|
|||||||
"0" \
|
"0" \
|
||||||
"Exit status 0"
|
"Exit status 0"
|
||||||
|
|
||||||
warn "Hello world!" 2> $TEST_PT_TMPDIR/log
|
warn "Hello world C!" 2> $TEST_PT_TMPDIR/log
|
||||||
cmd_ok \
|
cmd_ok \
|
||||||
"grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \
|
"grep -q 'Hello world C!' $TEST_PT_TMPDIR/log" \
|
||||||
"warn msg"
|
"warn msg"
|
||||||
|
|
||||||
warn "Hello" "world!" 2> $TEST_PT_TMPDIR/log
|
warn "Hello" "world D!" 2> $TEST_PT_TMPDIR/log
|
||||||
cmd_ok \
|
cmd_ok \
|
||||||
"grep -q 'Hello world!' $TEST_PT_TMPDIR/log" \
|
"grep -q 'Hello world D!' $TEST_PT_TMPDIR/log" \
|
||||||
"warn msg msg"
|
"warn msg msg"
|
||||||
|
|
||||||
is \
|
is \
|
||||||
@@ -34,6 +32,81 @@ is \
|
|||||||
"1" \
|
"1" \
|
||||||
"Exit status 1"
|
"Exit status 1"
|
||||||
|
|
||||||
|
OPT_VERBOSE=1
|
||||||
|
|
||||||
|
info "Hello world 1!" > $TEST_PT_TMPDIR/log
|
||||||
|
file_is_empty \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"verbose=1 info"
|
||||||
|
|
||||||
|
log "Hello world 2!" > $TEST_PT_TMPDIR/log
|
||||||
|
file_is_empty \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"verbose=1 log"
|
||||||
|
|
||||||
|
warn "Hello world 3!" > $TEST_PT_TMPDIR/log 2>&1
|
||||||
|
file_contains \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"Hello world 3!" \
|
||||||
|
"verbose=1 warn"
|
||||||
|
|
||||||
|
OPT_VERBOSE=2
|
||||||
|
|
||||||
|
info "Hello world 4!" > $TEST_PT_TMPDIR/log
|
||||||
|
file_is_empty \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"verbose=2 info"
|
||||||
|
|
||||||
|
log "Hello world 5!" > $TEST_PT_TMPDIR/log
|
||||||
|
file_contains \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"Hello world 5!" \
|
||||||
|
"verbose=2 log"
|
||||||
|
|
||||||
|
warn "Hello world 6!" > $TEST_PT_TMPDIR/log 2>&1
|
||||||
|
file_contains \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"Hello world 6!" \
|
||||||
|
"verbose=2 warn"
|
||||||
|
|
||||||
|
OPT_VERBOSE=3
|
||||||
|
|
||||||
|
info "Hello world 7!" > $TEST_PT_TMPDIR/log
|
||||||
|
file_contains \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"Hello world 7!" \
|
||||||
|
"verbose=3 info"
|
||||||
|
|
||||||
|
log "Hello world 8!" > $TEST_PT_TMPDIR/log
|
||||||
|
file_contains \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"Hello world 8!" \
|
||||||
|
"verbose=3 log"
|
||||||
|
|
||||||
|
warn "Hello world 9!" > $TEST_PT_TMPDIR/log 2>&1
|
||||||
|
file_contains \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"Hello world 9!" \
|
||||||
|
"verbose=3 warn"
|
||||||
|
|
||||||
|
OPT_VERBOSE=0
|
||||||
|
|
||||||
|
info "Hello world 10!" > $TEST_PT_TMPDIR/log
|
||||||
|
file_is_empty \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"verbose=0 info"
|
||||||
|
|
||||||
|
log "Hello world 11!" > $TEST_PT_TMPDIR/log
|
||||||
|
file_is_empty \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"verbose=0 log"
|
||||||
|
|
||||||
|
warn "Hello world 12!" > $TEST_PT_TMPDIR/log 2>&1
|
||||||
|
file_is_empty \
|
||||||
|
$TEST_PT_TMPDIR/log \
|
||||||
|
"verbose=0 warn"
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
# Done
|
# Done
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
|
done_testing
|
||||||
|
24
t/pt-stalk/option_sanity.t
Normal file
24
t/pt-stalk/option_sanity.t
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||||
|
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||||
|
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||||
|
};
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings FATAL => 'all';
|
||||||
|
use English qw(-no_match_vars);
|
||||||
|
use Test::More;
|
||||||
|
|
||||||
|
use PerconaTest;
|
||||||
|
|
||||||
|
my $output = `$trunk/bin/pt-stalk --help`;
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/^\s+--verbose\s+2/m,
|
||||||
|
"Default --verbose=2"
|
||||||
|
);
|
||||||
|
|
||||||
|
done_testing;
|
@@ -28,11 +28,28 @@ my $cnf = "/tmp/12345/my.sandbox.cnf";
|
|||||||
my $pid_file = "/tmp/pt-stalk.pid.$PID";
|
my $pid_file = "/tmp/pt-stalk.pid.$PID";
|
||||||
my $log_file = "/tmp/pt-stalk.log.$PID";
|
my $log_file = "/tmp/pt-stalk.log.$PID";
|
||||||
my $dest = "/tmp/pt-stalk.collect.$PID";
|
my $dest = "/tmp/pt-stalk.collect.$PID";
|
||||||
|
my $int_file = "/tmp/pt-stalk-after-interval-sleep";
|
||||||
my $pid;
|
my $pid;
|
||||||
|
|
||||||
diag(`rm $pid_file 2>/dev/null`);
|
sub cleanup {
|
||||||
diag(`rm $log_file 2>/dev/null`);
|
diag(`rm $pid_file $log_file $int_file 2>/dev/null`);
|
||||||
diag(`rm -rf $dest 2>/dev/null`);
|
diag(`rm -rf $dest 2>/dev/null`);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub wait_n_cycles {
|
||||||
|
my ($n) = @_;
|
||||||
|
PerconaTest::wait_until(
|
||||||
|
sub {
|
||||||
|
return 0 unless -f "$dest/after_interval_sleep";
|
||||||
|
my $n_cycles = `wc -l "$dest/after_interval_sleep" | awk '{print \$1}'`;
|
||||||
|
$n_cycles ||= '';
|
||||||
|
chomp($n_cycles);
|
||||||
|
return ($n_cycles || 0) >= $n;
|
||||||
|
},
|
||||||
|
1.5,
|
||||||
|
15
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
# Test that it won't run if can't connect to MySQL.
|
# Test that it won't run if can't connect to MySQL.
|
||||||
@@ -56,11 +73,14 @@ is(
|
|||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
# Test that it runs and dies normally.
|
# Test that it runs and dies normally.
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
diag(`rm $pid_file 2>/dev/null`);
|
|
||||||
diag(`rm $log_file 2>/dev/null`);
|
|
||||||
diag(`rm -rf $dest 2>/dev/null`);
|
|
||||||
|
|
||||||
$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest -- --defaults-file=$cnf");
|
cleanup();
|
||||||
|
|
||||||
|
# As of v2.1.9 when --verbose was added, non-matching checks are not
|
||||||
|
# printed by default. So we use the --plugin to tell us when the tool
|
||||||
|
# has completed a cycle.
|
||||||
|
|
||||||
|
$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf");
|
||||||
|
|
||||||
is(
|
is(
|
||||||
$retval >> 8,
|
$retval >> 8,
|
||||||
@@ -94,21 +114,16 @@ is(
|
|||||||
"pt-stalk is running"
|
"pt-stalk is running"
|
||||||
);
|
);
|
||||||
|
|
||||||
PerconaTest::wait_for_sh("grep -q 'Check results' $log_file >/dev/null");
|
wait_n_cycles(2);
|
||||||
|
PerconaTest::kill_program(pid_file => $pid_file);
|
||||||
|
|
||||||
$output = `cat $log_file 2>/dev/null`;
|
$output = `cat $log_file 2>/dev/null`;
|
||||||
like(
|
unlike(
|
||||||
$output,
|
$output,
|
||||||
qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/,
|
qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/,
|
||||||
"Check results logged"
|
"Non-matching results not logged because --verbose=2"
|
||||||
) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
|
) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
|
||||||
|
|
||||||
$retval = system("kill $pid 2>/dev/null");
|
|
||||||
is(
|
|
||||||
$retval >> 0,
|
|
||||||
0,
|
|
||||||
"Killed pt-stalk"
|
|
||||||
);
|
|
||||||
|
|
||||||
PerconaTest::wait_until(sub { !-f $pid_file });
|
PerconaTest::wait_until(sub { !-f $pid_file });
|
||||||
|
|
||||||
ok(
|
ok(
|
||||||
@@ -123,12 +138,56 @@ like(
|
|||||||
"Caught signal logged"
|
"Caught signal logged"
|
||||||
) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
|
) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
|
||||||
|
|
||||||
|
# #############################################################################
|
||||||
|
# --verbose 3 (non-matching results)
|
||||||
|
# #############################################################################
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
|
||||||
|
$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --verbose 3 -- --defaults-file=$cnf");
|
||||||
|
|
||||||
|
PerconaTest::wait_for_files($pid_file, $log_file);
|
||||||
|
PerconaTest::wait_for_sh("grep -q 'Check results' $log_file >/dev/null");
|
||||||
|
PerconaTest::kill_program(pid_file => $pid_file);
|
||||||
|
|
||||||
|
$output = `cat $log_file 2>/dev/null`;
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/Check results: Threads_running=\d+, matched=no, cycles_true=0/,
|
||||||
|
"Matching results logged with --verbose 3"
|
||||||
|
) or diag(`cat $log_file 2>/dev/null`, `cat $dest/*-output 2>/dev/null`);
|
||||||
|
|
||||||
|
# #############################################################################
|
||||||
|
# --verbose 1 (just errors and warnings)
|
||||||
|
# #############################################################################
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
|
||||||
|
$retval = system("$trunk/bin/pt-stalk --daemonize --pid $pid_file --log $log_file --dest $dest --verbose 1 --plugin $trunk/t/pt-stalk/samples/plugin002.sh -- --defaults-file=$cnf");
|
||||||
|
|
||||||
|
PerconaTest::wait_for_files($pid_file, $log_file);
|
||||||
|
wait_n_cycles(2);
|
||||||
|
PerconaTest::kill_program(pid_file => $pid_file);
|
||||||
|
|
||||||
|
$output = `cat $log_file 2>/dev/null`;
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/Caught signal, exiting/,
|
||||||
|
"Warning logged (--verbose 1)"
|
||||||
|
);
|
||||||
|
|
||||||
|
unlike(
|
||||||
|
$output,
|
||||||
|
qr/Start|Collect|Check/i,
|
||||||
|
"No run info log (--verbose 1)"
|
||||||
|
);
|
||||||
|
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
# Test collect.
|
# Test collect.
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
diag(`rm $pid_file 2>/dev/null`);
|
|
||||||
diag(`rm $log_file 2>/dev/null`);
|
cleanup();
|
||||||
diag(`rm $dest/* 2>/dev/null`);
|
|
||||||
|
|
||||||
# We'll have to watch Uptime since it's the only status var that's going
|
# We'll have to watch Uptime since it's the only status var that's going
|
||||||
# to be predictable.
|
# to be predictable.
|
||||||
@@ -180,10 +239,10 @@ like(
|
|||||||
"Trigger file logs how pt-stalk was ran"
|
"Trigger file logs how pt-stalk was ran"
|
||||||
);
|
);
|
||||||
|
|
||||||
chomp($output = `cat $log_file 2>/dev/null | grep 'Collector PID'`);
|
chomp($output = `cat $log_file 2>/dev/null | grep 'Collect [0-9] PID'`);
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr/Collector PID \d+/,
|
qr/Collect 1 PID \d+/,
|
||||||
"Collector PID logged"
|
"Collector PID logged"
|
||||||
)
|
)
|
||||||
or diag(
|
or diag(
|
||||||
@@ -195,9 +254,8 @@ or diag(
|
|||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
# Triggered but --no-collect.
|
# Triggered but --no-collect.
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
diag(`rm $pid_file 2>/dev/null`);
|
|
||||||
diag(`rm $log_file 2>/dev/null`);
|
cleanup();
|
||||||
diag(`rm $dest/* 2>/dev/null`);
|
|
||||||
|
|
||||||
(undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");
|
(undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");
|
||||||
$threshold = $uptime + 2;
|
$threshold = $uptime + 2;
|
||||||
@@ -209,7 +267,7 @@ PerconaTest::wait_until(sub { !-f $pid_file });
|
|||||||
$output = `cat $log_file 2>/dev/null`;
|
$output = `cat $log_file 2>/dev/null`;
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr/Collect triggered/,
|
qr/Collect 1 triggered/,
|
||||||
"Collect triggered"
|
"Collect triggered"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -227,6 +285,8 @@ ok(
|
|||||||
# --config
|
# --config
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
|
||||||
diag(`cp $ENV{HOME}/.pt-stalk.conf $ENV{HOME}/.pt-stalk.conf.original 2>/dev/null`);
|
diag(`cp $ENV{HOME}/.pt-stalk.conf $ENV{HOME}/.pt-stalk.conf.original 2>/dev/null`);
|
||||||
diag(`cp $trunk/t/pt-stalk/samples/config001.conf $ENV{HOME}/.pt-stalk.conf`);
|
diag(`cp $trunk/t/pt-stalk/samples/config001.conf $ENV{HOME}/.pt-stalk.conf`);
|
||||||
|
|
||||||
@@ -254,9 +314,8 @@ diag(`cp $ENV{HOME}/.pt-stalk.conf.original $ENV{HOME}/.pt-stalk.conf 2>/dev/nul
|
|||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Don't stalk, just collect.
|
# Don't stalk, just collect.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
diag(`rm $pid_file 2>/dev/null`);
|
|
||||||
diag(`rm $log_file 2>/dev/null`);
|
cleanup();
|
||||||
diag(`rm $dest/* 2>/dev/null`);
|
|
||||||
|
|
||||||
$retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --prefix nostalk --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1");
|
$retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 2 --dest $dest --prefix nostalk --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1");
|
||||||
|
|
||||||
@@ -343,9 +402,7 @@ unlike(
|
|||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
diag(`rm $pid_file 2>/dev/null`);
|
cleanup();
|
||||||
diag(`rm $log_file 2>/dev/null`);
|
|
||||||
diag(`rm -rf $dest 2>/dev/null`);
|
diag(`rm -rf $dest 2>/dev/null`);
|
||||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
5
t/pt-stalk/samples/plugin002.sh
Normal file
5
t/pt-stalk/samples/plugin002.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
after_interval_sleep() {
|
||||||
|
date >> "$OPT_DEST/after_interval_sleep"
|
||||||
|
}
|
@@ -100,6 +100,7 @@ run_test() {
|
|||||||
result() {
|
result() {
|
||||||
local result=$1
|
local result=$1
|
||||||
local test_name=${2:-""}
|
local test_name=${2:-""}
|
||||||
|
testno=$((testno + 1))
|
||||||
if [ $result -eq 0 ]; then
|
if [ $result -eq 0 ]; then
|
||||||
echo "ok $testno - $TEST_FILE $test_name"
|
echo "ok $testno - $TEST_FILE $test_name"
|
||||||
else
|
else
|
||||||
@@ -110,7 +111,6 @@ result() {
|
|||||||
cat $TEST_PT_TMPDIR/failed_result | sed -e 's/^/# /' -e '30q' >&2
|
cat $TEST_PT_TMPDIR/failed_result | sed -e 's/^/# /' -e '30q' >&2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
testno=$((testno + 1))
|
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,19 +121,21 @@ plan() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done_testing() {
|
||||||
|
echo "1..$testno"
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# The following subs are for the test files to call.
|
# The following subs are for the test files to call.
|
||||||
#
|
#
|
||||||
|
|
||||||
pass() {
|
pass() {
|
||||||
local reason="${1:-""}"
|
local reason="${1:-""}"
|
||||||
|
|
||||||
result 0 "$reason"
|
result 0 "$reason"
|
||||||
}
|
}
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
local reason="${1:-""}"
|
local reason="${1:-""}"
|
||||||
|
|
||||||
result 1 "$reason"
|
result 1 "$reason"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +179,42 @@ is() {
|
|||||||
result $? "$test_name"
|
result $? "$test_name"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_is_empty() {
|
||||||
|
local file=$1
|
||||||
|
local test_name=${2:-""}
|
||||||
|
test_command="-s $file"
|
||||||
|
if [ ! -f "$file" ]; then
|
||||||
|
echo "$file does not exist" > $TEST_PT_TMPDIR/failed_result
|
||||||
|
result 1 "$test_name"
|
||||||
|
fi
|
||||||
|
if [ -s "$file" ]; then
|
||||||
|
echo "$file is not empty:" > $TEST_PT_TMPDIR/failed_result
|
||||||
|
cat "$file" >> $TEST_PT_TMPDIR/failed_result
|
||||||
|
result 1 "$test_name"
|
||||||
|
else
|
||||||
|
result 0 "$test_name"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
file_contains() {
|
||||||
|
local file="$1"
|
||||||
|
local pat="$2"
|
||||||
|
local test_name=${3:-""}
|
||||||
|
test_command="grep -q '$pat' '$file'"
|
||||||
|
if [ ! -f "$file" ]; then
|
||||||
|
echo "$file does not exist" > $TEST_PT_TMPDIR/failed_result
|
||||||
|
result 1 "$test_name"
|
||||||
|
fi
|
||||||
|
grep -q "$pat" $file
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "$file does not contain '$pat':" > $TEST_PT_TMPDIR/failed_result
|
||||||
|
cat "$file" >> $TEST_PT_TMPDIR/failed_result
|
||||||
|
result 1 "$test_name"
|
||||||
|
else
|
||||||
|
result 0 "$test_name"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cmd_ok() {
|
cmd_ok() {
|
||||||
local test_command=$1
|
local test_command=$1
|
||||||
local test_name=${2:-""}
|
local test_name=${2:-""}
|
||||||
@@ -226,7 +264,7 @@ diag() {
|
|||||||
# Script starts here
|
# Script starts here
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|
||||||
testno=1
|
testno=0
|
||||||
failed_tests=0
|
failed_tests=0
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
|
Reference in New Issue
Block a user