mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-27 07:54:58 +00:00
Merge lp:~daniel-nichter/percona-toolkit/bash-tool-libs r133.
This commit is contained in:
25
bin/pt-stalk
25
bin/pt-stalk
@@ -320,31 +320,34 @@ set -u
|
||||
|
||||
disk_space() {
|
||||
local filesystem=${1:-"$PWD"}
|
||||
df -m $filesystem
|
||||
df -P -k $filesystem
|
||||
}
|
||||
|
||||
check_disk_space() {
|
||||
local file=$1
|
||||
local mb=${2:-"0"}
|
||||
local pc=${3:-"0"}
|
||||
local margin=${4:-"0"}
|
||||
local mb_margin=${4:-"0"}
|
||||
|
||||
local mb_used=$(cat $file | awk '/^\//{print $3}');
|
||||
local mb_free=$(cat $file | awk '/^\//{print $4}');
|
||||
local kb=$(($mb * 1024))
|
||||
local kb_margin=$(($mb_margin * 1024))
|
||||
|
||||
local kb_used=$(cat $file | awk '/^\//{print $3}');
|
||||
local kb_free=$(cat $file | awk '/^\//{print $4}');
|
||||
local pc_used=$(cat $file | awk '/^\//{print $5}' | sed -e 's/%//g');
|
||||
|
||||
if [ "$margin" -gt "0" ]; then
|
||||
local mb_total=$(($mb_used + $mb_free))
|
||||
if [ "$kb_margin" -gt "0" ]; then
|
||||
local kb_total=$(($kb_used + $kb_free))
|
||||
|
||||
mb_used=$(($mb_used + $margin))
|
||||
mb_free=$(($mb_free - $margin))
|
||||
pc_used=$(awk "BEGIN { printf(\"%d\", $mb_used/$mb_total * 100) }")
|
||||
kb_used=$(($kb_used + $kb_margin))
|
||||
kb_free=$(($kb_free - $kb_margin))
|
||||
pc_used=$(awk "BEGIN { printf(\"%d\", $kb_used/$kb_total * 100) }")
|
||||
fi
|
||||
|
||||
local pc_free=$((100 - $pc_used))
|
||||
|
||||
if [ "$mb_free" -le "$mb" -o "$pc_free" -le "$pc" ]; then
|
||||
warn "Not enough free disk space: ${pc_free}% free, ${mb_free} MB free; wanted more than ${pc}% free or ${mb} MB free"
|
||||
if [ "$kb_free" -le "$kb" -o "$pc_free" -le "$pc" ]; then
|
||||
warn "Not enough free disk space: ${pc_free}% free, ${kb_free} KB free; wanted more than ${pc}% free or ${kb} KB free"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
Reference in New Issue
Block a user