1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

M #~: Improve monitor_ds (#4243)

This commit is contained in:
Jan Orel 2020-02-26 19:09:45 +01:00 committed by GitHub
parent 3b50732c98
commit af18bceab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,48 +25,54 @@ REMOTES_DIR="${DRIVER_PATH}/../.."
mkdir -p "$DATASTORE_LOCATION"
USED_MB=$(df -B1M -P $DATASTORE_LOCATION 2>/dev/null | tail -n 1 | awk '{print $3}')
TOTAL_MB=$(df -B1M -P $DATASTORE_LOCATION 2>/dev/null | tail -n 1 | awk '{print $2}')
FREE_MB=$(df -B1M -P $DATASTORE_LOCATION 2>/dev/null | tail -n 1 | awk '{print $4}')
declare -A SEEN
read -r SRC DS_TOTAL_MB DS_USED_MB DS_FREE_MB \
<<< $(df -B1M --output=source,size,used,avail $DATASTORE_LOCATION \
2>/dev/null | tail -n1)
USED_MB=${USED_MB:-"0"}
TOTAL_MB=${TOTAL_MB:-"0"}
FREE_MB=${FREE_MB:-"0"}
# mark the the datasore location SRC as seen
SEEN[$SRC]=1
echo "DS_LOCATION_USED_MB=$USED_MB"
echo "DS_LOCATION_TOTAL_MB=$TOTAL_MB"
echo "DS_LOCATION_FREE_MB=$FREE_MB"
for DS in $(ls $DATASTORE_LOCATION); do
echo $DS | grep -q -E '^[0123456789]+$' || continue
dirs=$(ls $DATASTORE_LOCATION)
DIR=$DATASTORE_LOCATION/$DS
for ds in $dirs; do
echo $ds | grep -q -E '^[0123456789]+$' || continue
test -d "$DIR" || continue
dir=$DATASTORE_LOCATION/$ds
test -d "$dir" || continue
USED_MB=$(df -B1M -P $dir 2>/dev/null | tail -n 1 | awk '{print $3}')
TOTAL_MB=$(df -B1M -P $dir 2>/dev/null | tail -n 1 | awk '{print $2}')
FREE_MB=$(df -B1M -P $dir 2>/dev/null | tail -n 1 | awk '{print $4}')
read -r SRC TOTAL_MB USED_MB FREE_MB \
<<< $(df -B1M --output=source,size,used,avail $DIR \
2>/dev/null | tail -n1)
USED_MB=${USED_MB:-"0"}
TOTAL_MB=${TOTAL_MB:-"0"}
FREE_MB=${FREE_MB:-"0"}
echo "DS = ["
echo " ID = $ds,"
echo " ID = $DS,"
echo " USED_MB = $USED_MB,"
echo " TOTAL_MB = $TOTAL_MB,"
echo " FREE_MB = $FREE_MB"
echo "]"
# Skip if datastore is not marked for local monitoring
[ -e "${dir}/.monitor" ] || continue
# If didn't seen yet add it to the total
if [ "${SEEN[$SRC]}" = "" ]; then
SEEN[$SRC]=1
DS_USED_MB=$((( $DS_USED_MB + $USED_MB )))
DS_TOTAL_MB=$((( $DS_TOTAL_MB + $TOTAL_MB )))
DS_FREE_MB=$((( $DS_FREE_MB + $FREE_MB )))
fi
DRIVER=$(cat ${dir}/.monitor)
# Skip if datastore is not marked for local monitoring
[ -e "${DIR}/.monitor" ] || continue
DRIVER=$(cat ${DIR}/.monitor)
[ -z "$DRIVER" ] && DRIVER="ssh" # default is ssh
SCRIPT_PATH="${REMOTES_DIR}/tm/$DRIVER/monitor_ds"
[ -e "$SCRIPT_PATH" ] && "$SCRIPT_PATH" "$dir"
[ -e "$SCRIPT_PATH" ] && "$SCRIPT_PATH" "$DIR"
done
echo "DS_LOCATION_USED_MB=$DS_USED_MB"
echo "DS_LOCATION_TOTAL_MB=$DS_TOTAL_MB"
echo "DS_LOCATION_FREE_MB=$DS_FREE_MB"