1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

feature #3335: Use MAX AVAIL to compute Ceph datastore usage

This commit is contained in:
Ruben S. Montero 2015-02-17 15:23:05 +01:00
parent be65145b93
commit 8174fe08bc
2 changed files with 27 additions and 9 deletions

View File

@ -67,18 +67,35 @@ fi
# ------------ Compute datastore usage -------------
MONITOR_SCRIPT=$(cat <<EOF
$RADOS df -p ${POOL_NAME}| $AWK '{
if (\$1 == "total") {
to_mb() {
value=\$(echo "\$1" | sed 's/[^0123456789].*\$//g')
units=\$(echo "\$1" | sed 's/^[0123456789]*//g' | tr '[:upper:]' '[:lower:]')
space = int(\$3/1024)
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"
}
if (\$2 == "used") {var = "USED_MB"}
else if (\$2 == "avail") {var = "FREE_MB"}
else if (\$2 == "space") {var = "TOTAL_MB"}
REPSIZE=\$($CEPH osd pool get "$POOL_NAME" size | cut -d':' -f2)
MAXAVAIL=\$($CEPH df | grep "$POOL_NAME" | awk '{print \$5}')
USED=\$($CEPH df | grep "$POOL_NAME" | awk '{print \$3}')
TOTAL=\$($RADOS df | grep 'total space' | awk '{print \$3}')
print var "=" space
}
}'
USED_MB=\$(to_mb \$USED)
FREE_MB=\$(to_mb \$MAX_AVAIL)
TOTAL_MB=\$(expr \$TOTAL / 1024 / \$REPSIZE)
if [ \$FREE_MB -eq 0 ] ; then FREE_MB=\$(expr \$TOTAL_MB - \$USED_MB) ; fi
echo "USED_MB=\$USED_MB"
echo "FREE_MB=\$FREE_MB"
echo "TOTAL_MB=\$TOTAL_MB"
EOF
)

View File

@ -21,6 +21,7 @@ export PATH=/bin:/sbin:/usr/bin:$PATH
AWK=awk
BASH=bash
CUT=cut
CEPH=ceph
DATE=date
DD=dd
DF=df