Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
recon_growthforecast.sh
#!/bin/bash
PATH=/bin:/usr/bin; export PATH
GF_ENDPOINT="http://forecast.example.jp:5125/api"
SERVICE_NAME=$1
SECTION_NAME=$2
if [ -z "$1" -o -z "$2" ]; then
echo "$0 service_name section_name"
exit 1
fi
basename=$(basename $0)
RESULT=$(mktemp -q /tmp/$basename.XXXXXXXXXX)
swift-recon -d > $RESULT
space_used=$(cat $RESULT | grep 'space used' | awk '{print $5}')
space_free=$(cat $RESULT | grep 'space free' | awk '{print $5}')
disk_usage_min=$(cat $RESULT | grep 'lowest' | awk '{print $4}' | sed -e 's/[^0-9.]*//g')
disk_usage_max=$(cat $RESULT | grep 'lowest' | awk '{print $6}' | sed -e 's/[^0-9.]*//g')
disk_usage_avg=$(cat $RESULT | grep 'lowest' | awk '{print $8}' | sed -e 's/[^0-9.]*//g')
if [ "$space_used" -a "$space_free" -a "$disk_usage_min" -a "$disk_usage_max" -a "$disk_usage_avg" ]; then
disk_usage_min_100=$(echo "$disk_usage_min * 100 / 1" | bc)
disk_usage_max_100=$(echo "$disk_usage_max * 100 / 1" | bc)
disk_usage_avg_100=$(echo "$disk_usage_avg * 100 / 1" | bc)
effective_used=$(echo "$space_used / 3" | bc)
effective_free=$(echo "$space_free / 3" | bc)
# for debug
#echo "$space_used:$space_free:$effective_used:$effective_free:$disk_usage_min:$disk_usage_max:$disk_usage_avg"
rm $RESULT
curl -s -F number=$space_used $GF_ENDPOINT/$SERVICE_NAME/$SECTION_NAME/space_used > /dev/null
curl -s -F number=$space_free $GF_ENDPOINT/$SERVICE_NAME/$SECTION_NAME/space_free > /dev/null
curl -s -F number=$effective_used $GF_ENDPOINT/$SERVICE_NAME/$SECTION_NAME/effective_used > /dev/null
curl -s -F number=$effective_free $GF_ENDPOINT/$SERVICE_NAME/$SECTION_NAME/effective_free > /dev/null
curl -s -F number=$disk_usage_min_100 $GF_ENDPOINT/$SERVICE_NAME/$SECTION_NAME/usage_min > /dev/null
curl -s -F number=$disk_usage_max_100 $GF_ENDPOINT/$SERVICE_NAME/$SECTION_NAME/usage_max > /dev/null
curl -s -F number=$disk_usage_avg_100 $GF_ENDPOINT/$SERVICE_NAME/$SECTION_NAME/usage_avg > /dev/null
else
echo "swift-recon parse error."
echo "output($RESULT):"
cat $RESULT
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.