Added support for 'check' sync progress

This commit is contained in:
Gitea 2020-12-06 21:14:06 +01:00
parent 30a77ea9ba
commit 67d558dd2d
25 changed files with 53 additions and 23 deletions

View File

@ -57,8 +57,9 @@ CHUNK_SIZE_IN_BYTES= # size in bytes for chunks
NUM_DEVICES=0 # int with total number of devices in raid
NUM_ACTIVE_DEVICES=0 # int with number of active devices in raid
NUM_SPARE_DEVICES=0 # int with number of spare devices in raid
RECOVERY_PROGRESS= # float in percent
RECOVERY_SPEED= # sync speed in K/s
rYNC_ACTION= # "idle", "check" or "recover"
SYNC_PROGRESS= # float in percent
SYNC_SPEED= # sync speed in K/s
declare -A DEVICE_STATE # dict of strings. key = dev, value = state
declare -A FAULTY_DEVICES # dict with only faulty devices. key = dev, value = true
declare -A TO_REPLACE_DEVICES # dict of devices in raid that shall be replaced. key = dev, value = true
@ -71,15 +72,19 @@ function getDataFromSys {
CHUNK_SIZE_IN_BYTES=$(<$INPUT/chunk_size)
SIZE_IN_BLOCKS=$(<$INPUT/component_size)
STATE=$(<$INPUT/array_state)
RECOVERY_PROGRESS=$(<$INPUT/sync_completed)
RECOVERY_SPEED=$(<$INPUT/sync_speed)
SYNC_ACTION=$(<$INPUT/sync_action)
if [ "$SYNC_ACTION" != "idle" ]; then
SYNC_PROGRESS=$(<$INPUT/sync_completed)
SYNC_SPEED=$(<$INPUT/sync_speed)
fi
log "LEVEL = $LEVEL"
log "STATE = $STATE"
log "CHUNK_SIZE_IN_BYTES = $CHUNK_SIZE_IN_BYTES"
log "SIZE_IN_BLOCKS = $SIZE_IN_BLOCKS"
log "RECOVERY_PROGRESS = $RECOVERY_PROGRESS"
log "RECOVERY_SPEED = $RECOVERY_SPEED"
log "SYNC_ACTION = $SYNC_ACTION"
log "SYNC_PROGRESS = $SYNC_PROGRESS"
log "SYNC_SPEED = $SYNC_SPEED"
for dev in `find $INPUT -type d -name 'dev-*' -printf "%f\n"`; do
local deviceName=${dev:4}
@ -106,15 +111,15 @@ function getDataFromSys {
log "FAULTY_DEVICES = ${FAULTY_DEVICES[*]}"
log "TO_REPLACE_DEVICES = ${TO_REPLACE_DEVICES[*]}"
if [ "$RECOVERY_PROGRESS" != "none" ]; then
RECOVERY_NUM=${RECOVERY_PROGRESS% /*}
log "'$RECOVERY_NUM'"
RECOVERY_DEN=${RECOVERY_PROGRESS#*/ }
log "'$RECOVERY_DEN'"
RECOVERY_PERCENT=$(($RECOVERY_NUM*100/$RECOVERY_DEN))
if [ "$SYNC_ACTION" != "idle" ]; then
SYNC_NUM=${SYNC_PROGRESS% /*}
log "'$SYNC_NUM'"
SYNC_DEN=${SYNC_PROGRESS#*/ }
log "'$SYNC_DEN'"
SYNC_PERCENT=$(($SYNC_NUM*100/$SYNC_DEN))
BLOCK_SIZE=$(<$(dirname $INPUT)/queue/hw_sector_size)
RECOVERY_REMAINING_S=$(( ($RECOVERY_DEN-$RECOVERY_NUM)*$BLOCK_SIZE/1024/$RECOVERY_SPEED))
RECOVERY_REMAINING_MIN=$(($RECOVERY_REMAINING_S/60))
SYNC_REMAINING_S=$(( ($SYNC_DEN-$SYNC_NUM)*$BLOCK_SIZE/1024/$SYNC_SPEED))
SYNC_REMAINING_MIN=$(($SYNC_REMAINING_S/60))
fi
}
@ -140,10 +145,14 @@ function printOutputAndExit {
info="${info}These devices should be replaced: ${!TO_REPLACE_DEVICES[@]}"
fi
if [ "$RECOVERY_PROGRESS" != "none" ]; then
if [ "$SYNC_ACTION" == "recover" ]; then
if [ -z "$result" ]; then result="WARNING"; fi
if [ -n "$info" ]; then info="$info. "; fi
info="${info}Recovering: $RECOVERY_PERCENT%, remaining ${RECOVERY_REMAINING_MIN}min"
info="${info}Recovering: $SYNC_PERCENT%, remaining ${SYNC_REMAINING_MIN}min"
fi
if [ "$SYNC_ACTION" == "check" ]; then
if [ -n "$info" ]; then info="$info. "; fi
info="${info}Checking: $SYNC_PERCENT%, remaining ${SYNC_REMAINING_MIN}min"
fi
if [ -z "$result" ]; then result="OK"; fi
@ -160,12 +169,10 @@ function printOutputAndExit {
echo -n " 'num active devices'=$NUM_ACTIVE_DEVICES;;;0;$NUM_DEVICES"
echo -n " 'num failed devices'=${#FAILED_DEVICES[@]};;1;0;$NUM_DEVICES"
echo -n " 'num spare devices'=$NUM_SPARE_DEVICES;;;0"
if [ "$RECOVERY_PROGRESS" != "none" ]; then
if [ -z "$result" ]; then result="WARNING"; fi
if [ -n "$info" ]; then info="$info. "; fi
echo -n " 'recovery progress'=$RECOVERY_NUM;0;;0;$RECOVERY_DEN"
echo -n " 'recovery speed [1/s]'=${RECOVERY_SPEED}K"
echo -n " 'recovery remaining'=${RECOVERY_REMAINING_S}s"
if [ "$SYNC_ACTION" != "idle" ]; then
echo -n " 'sync progress'=$SYNC_NUM;0;;0;$SYNC_DEN"
echo -n " 'sync speed [1/s]'=${SYNC_SPEED}K"
echo -n " 'sync remaining'=${SYNC_REMAINING_S}s"
fi
for dev in ${!DEVICE_STATE[@]}; do
echo -n " 'dev $dev: ${DEVICE_STATE[$dev]}"

View File

@ -0,0 +1 @@
default

View File

@ -0,0 +1 @@
clean

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
976431104

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
2

View File

@ -0,0 +1 @@
in_sync

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1 @@
in_sync

View File

@ -0,0 +1 @@
0

View File

@ -0,0 +1 @@
in_sync

View File

@ -0,0 +1 @@
check

View File

@ -0,0 +1 @@
raid1

View File

@ -0,0 +1 @@
20

View File

@ -0,0 +1 @@
3

View File

@ -0,0 +1 @@
dev-sdc1

View File

@ -0,0 +1 @@
dev-sdb1

View File

@ -0,0 +1 @@
dev-sda1

View File

@ -0,0 +1 @@
check

View File

@ -0,0 +1 @@
1893234560 / 1952862208

View File

@ -0,0 +1 @@
13718

View File

@ -0,0 +1 @@
512

1
test/checking.output Normal file
View File

@ -0,0 +1 @@
OK: Checking: 96%, remaining 36min | 'raid level: raid1'=0 'size in blocks'=976431104 'num devices'=3 'num active devices'=3;;;0;3 'num failed devices'=0;;1;0;3 'num spare devices'=0;;;0 'sync progress'=1893234560;0;;0;1952862208 'sync speed [1/s]'=13718K 'sync remaining'=2173s 'dev sdc1: in_sync'=0 'dev sdb1: in_sync'=0 'dev sda1: in_sync'=0

View File

@ -1 +1 @@
CRITICAL: Missing 1 of 3 devices. Recovering: 88%, remaining 108min | 'raid level: raid1'=0 'size in blocks'=976431104 'num devices'=3 'num active devices'=2;;;0;3 'num failed devices'=0;;1;0;3 'num spare devices'=1;;;0 'recovery progress'=1728697856;0;;0;1952862208 'recovery speed [1/s]'=17170K 'recovery remaining'=6527s 'dev sdd1: spare'=0 'dev sdc1: in_sync'=0 'dev sda1: in_sync'=0
CRITICAL: Missing 1 of 3 devices. Recovering: 88%, remaining 108min | 'raid level: raid1'=0 'size in blocks'=976431104 'num devices'=3 'num active devices'=2;;;0;3 'num failed devices'=0;;1;0;3 'num spare devices'=1;;;0 'sync progress'=1728697856;0;;0;1952862208 'sync speed [1/s]'=17170K 'sync remaining'=6527s 'dev sdd1: spare'=0 'dev sdc1: in_sync'=0 'dev sda1: in_sync'=0