From 27e152c256083d4dc5c73431976eb7923fd60fd0 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 23 Jun 2016 12:12:54 +0200 Subject: [PATCH] bug #3953: Better ceph df parsing. Apply changes to Ceph System DS also --- src/datastore_mad/remotes/ceph/ceph_utils.sh | 30 ++++++++++++++++++++ src/datastore_mad/remotes/ceph/monitor | 18 ++---------- src/tm_mad/ceph/monitor | 30 +++----------------- 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/datastore_mad/remotes/ceph/ceph_utils.sh b/src/datastore_mad/remotes/ceph/ceph_utils.sh index f9726632e1..54b7a71438 100644 --- a/src/datastore_mad/remotes/ceph/ceph_utils.sh +++ b/src/datastore_mad/remotes/ceph/ceph_utils.sh @@ -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 +} + diff --git a/src/datastore_mad/remotes/ceph/monitor b/src/datastore_mad/remotes/ceph/monitor index 66613cb46e..61326dbccc 100755 --- a/src/datastore_mad/remotes/ceph/monitor +++ b/src/datastore_mad/remotes/ceph/monitor @@ -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 + diff --git a/src/tm_mad/ceph/monitor b/src/tm_mad/ceph/monitor index e3125a38a5..4e379d13c6 100755 --- a/src/tm_mad/ceph/monitor +++ b/src/tm_mad/ceph/monitor @@ -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 <&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