1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

bug #3953: Better ceph df parsing. Apply changes to Ceph System DS also

This commit is contained in:
Ruben S. Montero 2016-06-23 12:12:54 +02:00
parent 6a35e46203
commit 27e152c256
3 changed files with 37 additions and 41 deletions

View File

@ -177,3 +177,33 @@ rbd_rm_r() {
$RBD rm $rbd
fi
}
#--------------------------------------------------------------------------------
# Parse the output of rbd df in xml format and generates a monitor string for a
# Ceph pool. You **MUST** define XPATH util before using this function
# @param $1 the xml output of the command
# @param $2 the pool name
#--------------------------------------------------------------------------------
rbd_df_monitor() {
local monitor_data i j xpath_elements pool_name bytes_used free
monitor_data=$1
pool_name=$2
while IFS= read -r -d '' element; do
xpath_elements[i++]="$element"
done < <(echo $monitor_data | $XPATH \
"/stats/pools/pool[name = \"${pool_name}\"]/stats/bytes_used" \
"/stats/pools/pool[name = \"${pool_name}\"]/stats/max_avail")
bytes_used="${xpath_elements[j++]:-0}"
free="${xpath_elements[j++]:-0}"
cat << EOF | tr -d '[:blank:][:space:]'
USED_MB=$(($bytes_used / 1024**2))\n
TOTAL_MB=$((($bytes_used + $free) / 1024**2))\n
FREE_MB=$(($free / 1024**2))\n
EOF
}

View File

@ -33,6 +33,7 @@ fi
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../libfs.sh
source ${DRIVER_PATH}/ceph.conf
source ${DRIVER_PATH}/ceph_utils.sh
# -------- Get datastore arguments from OpenNebula core ------------
@ -83,22 +84,9 @@ MONITOR_STATUS=$?
if [ "$MONITOR_STATUS" = "0" ]; then
XPATH="${DRIVER_PATH}/../xpath.rb --stdin"
unset i j XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <(echo $MONITOR_DATA | $XPATH \
"/stats/pools/pool[name = \"${POOL_NAME}\"]/stats/bytes_used" \
"/stats/pools/pool[name = \"${POOL_NAME}\"]/stats/max_avail")
BYTES_USED="${XPATH_ELEMENTS[j++]}"
FREE="${XPATH_ELEMENTS[j++]}"
echo "USED_MB=$(($BYTES_USED / 1024**2))
TOTAL_MB=$((($BYTES_USED + $FREE) / 1024**2))
FREE_MB=$(($FREE / 1024**2))" | tr -d ' '
echo -e "$(rbd_df_monitor ${MONITOR_DATA} ${POOL_NAME})"
else
echo "$MONITOR_DATA"
exit $MONITOR_STATUS
fi

View File

@ -33,6 +33,7 @@ fi
DRIVER_PATH=$(dirname $0)
source ${DRIVER_PATH}/../../datastore/libfs.sh
source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf
source ${DRIVER_PATH}/../../datastore/ceph/ceph_utils.sh
# -------- Get datastore arguments from OpenNebula core ------------
@ -74,31 +75,7 @@ fi
# ------------ Compute datastore usage -------------
MONITOR_SCRIPT=$(cat <<EOF
to_mb() {
value=\$(echo "\$1" | sed 's/[^0123456789].*\$//g')
units=\$(echo "\$1" | sed 's/^[0123456789]*//g' | tr '[:upper:]' '[:lower:]')
case "\$units" in
t|tb) value=\$(expr \$value \* 1024 \* 1024) ;;
g|gb) value=\$(expr \$value \* 1024) ;;
m|mb) value=\$value ;;
k|kb) value=\$(expr \$value / 1024) ;;
b|'') value=0 ;;
*) value=0;;
esac
echo "\$value"
}
MAX_AVAIL=\$($CEPH df | grep "$POOL_NAME" | awk '{print \$5}')
USED=\$($CEPH df | grep "$POOL_NAME" | awk '{print \$3}')
USED_MB=\$(to_mb \$USED)
FREE_MB=\$(to_mb \$MAX_AVAIL)
TOTAL_MB=\$(expr \$USED_MB + \$FREE_MB)
echo "USED_MB=\$USED_MB"
echo "FREE_MB=\$FREE_MB"
echo "TOTAL_MB=\$TOTAL_MB"
$CEPH df --format xml
EOF
)
@ -106,7 +83,8 @@ MONITOR_DATA=$(ssh_monitor_and_log $HOST "$MONITOR_SCRIPT" 2>&1)
MONITOR_STATUS=$?
if [ "$MONITOR_STATUS" = "0" ]; then
echo "$MONITOR_DATA" | tr ' ' '\n'
XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin"
echo -e "$(rbd_df_monitor ${MONITOR_DATA} ${POOL_NAME})"
else
echo "$MONITOR_DATA"
exit $MONITOR_STATUS