Created
October 27, 2011 14:46
-
-
Save chmouel/1319740 to your computer and use it in GitHub Desktop.
Get account stats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
#CONFIGURE THIS | |
AUTH_URL= | |
SUPER_ADMIN_KEY= | |
[[ -z ${AUTH_URL} || -z ${SUPER_ADMIN_KEY} ]] && { echo "Configure this script by vim $0 and adjust the variable at the top"; exit 1 ;} | |
account="$1" | |
[[ -z ${account} ]] && { echo "Need an account on the command line" ; exit 1 ;} | |
ID=$(swauth-list -A ${AUTH_URL} -K ${SUPER_ADMIN_KEY} ${account} 2>/dev/null|sed 's/.*account_id": "//;s/".*//') | |
[[ -z ${ID} ]] && { echo "$account does not exist"; exit 1 ;} | |
CURL_CMD=$(swift-get-nodes /etc/swift/account.ring.gz ${ID} |sed -n -e '/curl/ { s/curl/curl -s/;s/"//g;p;Q }') | |
[[ -z ${CURL_CMD} ]] && { echo "error while getting information for $ID in the ring "; exit 1 ;} | |
function get_value() { | |
${CURL_CMD} | while read line;do | |
[[ $line != X-* ]] && continue | |
line=${line#X-} | |
key=${line%: *};key=${key//-/} | |
value=${line#*: } | |
value=$(echo ${value}|tr -d '\r') | |
echo "$key=$value" | |
done | |
} | |
eval $(get_value) | |
echo "Number of Containers: $AccountContainerCount" | |
echo "Number of Objects: $AccountObjectCount" | |
echo "Bytes used: $AccountBytesUsed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment