mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 05:29:30 +00:00
Implement --[no]collect.
This commit is contained in:
68
bin/pt-stalk
68
bin/pt-stalk
@@ -971,44 +971,48 @@ stalk() {
|
||||
# ##################################################################
|
||||
# Start collecting, maybe.
|
||||
# ##################################################################
|
||||
local prefix="${OPT_PREFIX:-$(date +%F-%T | tr :- _)}"
|
||||
log "Collect triggered"
|
||||
|
||||
# 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:
|
||||
if [ -n "$last_prefix" ]; then
|
||||
margin=$(du -mc "$OPT_DEST"/"$last_prefix"-* | tail -n 1 | awk '{print $1'})
|
||||
# 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
|
||||
disk_space "$OPT_DEST" > "$OPT_DEST/$prefix-disk-space"
|
||||
check_disk_space \
|
||||
"$OPT_DEST/$prefix-disk-space" \
|
||||
"$OPT_DISK_BYTE_LIMIT" \
|
||||
"$OPT_DISK_PCT_LIMIT" \
|
||||
"$margin" # real used MB + margin MB
|
||||
if [ $? -eq 0 ]; then
|
||||
# There should be enough disk space, so collect.
|
||||
log "$msg" >> "$OPT_DEST/$prefix-trigger"
|
||||
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"
|
||||
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:
|
||||
if [ -n "$last_prefix" ]; then
|
||||
margin=$(du -mc "$OPT_DEST"/"$last_prefix"-* | tail -n 1 | awk '{print $1'})
|
||||
fi
|
||||
disk_space "$OPT_DEST" > "$OPT_DEST/$prefix-disk-space"
|
||||
check_disk_space \
|
||||
"$OPT_DEST/$prefix-disk-space" \
|
||||
"$OPT_DISK_BYTE_LIMIT" \
|
||||
"$OPT_DISK_PCT_LIMIT" \
|
||||
"$margin" # real used MB + margin MB
|
||||
if [ $? -eq 0 ]; then
|
||||
# There should be enough disk space, so collect.
|
||||
log "$msg" >> "$OPT_DEST/$prefix-trigger"
|
||||
log "pt-stalk ran with $RAN_WITH" >> "$OPT_DEST/$prefix-trigger"
|
||||
last_prefix="$prefix"
|
||||
|
||||
# Fork and background the collect subroutine which will
|
||||
# run for --run-time seconds. We (the parent) sleep
|
||||
# while its collecting (hopefully --sleep is longer than
|
||||
# --run-time).
|
||||
(
|
||||
collect "$OPT_DEST" "$prefix"
|
||||
) >> "$OPT_DEST/$prefix-output" 2>&1 &
|
||||
else
|
||||
# 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"
|
||||
|
||||
# Fork and background the collect subroutine which will
|
||||
# run for --run-time seconds. We (the parent) sleep
|
||||
# while its collecting (hopefully --sleep is longer than
|
||||
# --run-time).
|
||||
(
|
||||
collect "$OPT_DEST" "$prefix"
|
||||
) >> "$OPT_DEST/$prefix-output" 2>&1 &
|
||||
else
|
||||
# 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
|
||||
|
||||
# ##################################################################
|
||||
|
@@ -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