mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-20 02:20:04 +08:00
Implement --[no]collect.
This commit is contained in:
18
bin/pt-stalk
18
bin/pt-stalk
@@ -971,9 +971,18 @@ stalk() {
|
||||
# ##################################################################
|
||||
# Start collecting, maybe.
|
||||
# ##################################################################
|
||||
local prefix="${OPT_PREFIX:-$(date +%F-%T | tr :- _)}"
|
||||
log "Collect triggered"
|
||||
|
||||
# Send email to whomever that collect has been triggered.
|
||||
if [ "$OPT_NOTIFY_BY_EMAIL" ]; then
|
||||
echo "$msg on $(hostname)" \
|
||||
| mail -s "Collect triggered on $(hostname)" \
|
||||
"$OPT_NOTIFY_BY_EMAIL"
|
||||
fi
|
||||
|
||||
if [ "$OPT_COLLECT" ]; then
|
||||
local prefix="${OPT_PREFIX:-$(date +%F-%T | tr :- _)}"
|
||||
|
||||
# Check if we'll have enough disk space to collect. Disk space
|
||||
# is also checked every interval while collecting.
|
||||
local margin="20" # default 20M margin, unless:
|
||||
@@ -992,12 +1001,6 @@ stalk() {
|
||||
log "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger"
|
||||
last_prefix="$prefix"
|
||||
|
||||
# Send email to whomever that collect has been triggered.
|
||||
if [ "$OPT_NOTIFY_BY_EMAIL" ]; then
|
||||
echo "$msg on $(hostname)" \
|
||||
| mail -s "Collect triggered on $(hostname)" \
|
||||
"$OPT_NOTIFY_BY_EMAIL"
|
||||
fi
|
||||
|
||||
# Fork and background the collect subroutine which will
|
||||
# run for --run-time seconds. We (the parent) sleep
|
||||
@@ -1010,6 +1013,7 @@ stalk() {
|
||||
# There will not be enough disk space, so do not collect.
|
||||
warn "Collect canceled because there will not be enough disk space after collecting another $margin MB"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ##################################################################
|
||||
# Done collecting.
|
||||
|
||||
@@ -24,7 +24,7 @@ if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 17;
|
||||
plan tests => 20;
|
||||
}
|
||||
|
||||
my $cnf = "/tmp/12345/my.sandbox.cnf";
|
||||
@@ -169,6 +169,38 @@ like(
|
||||
"Trigger file logs how pt-stalk was ran"
|
||||
);
|
||||
|
||||
# ###########################################################################
|
||||
# Triggered but --no-collect.
|
||||
# ###########################################################################
|
||||
diag(`rm $pid_file 2>/dev/null`);
|
||||
diag(`rm $log_file 2>/dev/null`);
|
||||
diag(`rm $dest/* 2>/dev/null`);
|
||||
|
||||
(undef, $uptime) = $dbh->selectrow_array("SHOW STATUS LIKE 'Uptime'");
|
||||
$threshold = $uptime + 2;
|
||||
|
||||
$retval = system("$trunk/bin/pt-stalk --no-collect --iterations 1 --dest $dest --variable Uptime --threshold $threshold --cycles 1 --run-time 1 --pid $pid_file -- --defaults-file=$cnf >$log_file 2>&1");
|
||||
|
||||
sleep 2;
|
||||
|
||||
$output = `cat $log_file`;
|
||||
like(
|
||||
$output,
|
||||
qr/Collect triggered/,
|
||||
"Collect triggered"
|
||||
);
|
||||
|
||||
ok(
|
||||
! -f "$dest/*",
|
||||
"No files collected"
|
||||
);
|
||||
|
||||
$output = `ps x | grep -v grep | grep 'pt-stalk pt-stalk --iterations 1 --dest $dest'`;
|
||||
is(
|
||||
$output,
|
||||
"",
|
||||
"pt-stalk is not running"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# --config
|
||||
|
||||
Reference in New Issue
Block a user