Skip to content

Instantly share code, notes, and snippets.

@dosaboy
Last active June 4, 2020 14:08
Show Gist options
  • Select an option

  • Save dosaboy/486ed50c25154819134772694d79ced5 to your computer and use it in GitHub Desktop.

Select an option

Save dosaboy/486ed50c25154819134772694d79ced5 to your computer and use it in GitHub Desktop.
#!/bin/bash -eu
#
# Origin: https://gist.github.com/dosaboy/486ed50c25154819134772694d79ced5
#
# Authors:
# - [email protected]
# - [email protected]
#
# Description:
# This tool takes as its input information about swift container locations as
# well as information about the physical locations (disks) in the cluster that
# currently hold the largest amount of container data and correlates the two
# to indentify whether the containers (replicas) in question are colocated
# with other large and/or numerours containers. The containers in this case
# were those created by a run of swift-bench.
#
# Containers that are located on disks that have high usage will have a
# "(container data=<size>)" message printed next to them. You will likely need to
# create a lot of containers in your test in order to achieve this for a
# moderately large cluster.
#
# Usage:
#
# Get info on where containers are located by doing this for each container
# and storing output in same file e.g.
#
# swift-get-nodes /etc/swift/container.ring.gz AUTH_d9a15a02704149c9a80972427e1294cf C1 > node_info
#
# Get info on storage node container physical sizes by doing this for each
# container from swift-bench test e.g.
#
# prefix=10.230
# for a in swift-storage-z{1..3}; do
# readarray -t units<<<"`juju status --format=json $a| jq -r '.applications[].units| to_entries[]| .key'`"
# for u in ${units[@]}; do
# echo "== $u"
# juju run -u $u -- "ip -4 a s | grep $prefix; du -hs /srv/node/bcache*/container*|sort -h|tail -3"; done
# done
# done > load_info
#
# Parse the info into something meaningful:
# ./script.sh node_info load_info
#
SWIFT_GET_NODES_OUTPUT=$1
CONTAINER_LOAD_INFO=$2
# Create ip->host converter
readarray -t hosts<<<"`sed -r -e 's,.*==\s+(swift-.+/[[:digit:]]),\1,g;s,.+\s+([[:digit:]\.]+/[[:digit:]]+).*,\1,g;t;d' $CONTAINER_LOAD_INFO`"
max=${#hosts[@]}
hostinfo_sedexpr="sed -r"
for ((i=0;i<max;i=i+2)); do
ip=`echo ${hosts[$((i+1))]}| sed -r 's,([[:digit:]\.]+)/.+,\1:[[:digit:]]+,g'| sed -r 's/\./\\\./g'`
hostinfo_sedexpr+=" -e 's,$ip,${hosts[$i]},g'"
done
# Create loaded device index and converter
readarray -t lines<<<"`egrep "^==|^[0-9\.]+[KMGTP]+" $CONTAINER_LOAD_INFO`"
max=${#lines[@]}
devinfo_sedexpr="sed -r"
# Looking for format e.g.
#
#== swift-storage-z3/13
#1.1G /srv/node/bcache19/containers
#14G /srv/node/bcache14/containers
#22G /srv/node/bcache16/containers
#
for ((i=1;i<max;i=i+1)); do
prev=${lines[$((i-1))]}
curr=${lines[$i]}
egrep -q "^==" <<< $prev && egrep -q "^==" <<< $curr && continue
dev=`echo $curr| sed -r 's,.+/(bcache[[:digit:]]+)/.+,\1,g;t;d'`
size=`echo $curr| sed -r 's,(.+)\s+.+/bcache.+,\1,g;t;d'`
[ -n "$dev" ] || continue
_host_name=`echo $prev| sed -r 's,==\s+(.+)/(.+),\1\\\/\2,g;t;d'`
[ -n "$_host_name" ] && host_name=$_host_name
grep -q bcache <<< $curr && grep -q "==" <<< $prev || \
grep -q bcache <<< $curr && devinfo_sedexpr+=" -e 's/($host_name\s+$dev)$/\1 (container data=$size)/g'" || true
done
# Show container locations with device info
tmp=`mktemp`
cp $SWIFT_GET_NODES_OUTPUT $tmp
echo "__EOF__" >> $tmp
account=`grep Account $tmp| awk '{print $2}'`
readarray -t containers<<<"`grep Container $tmp| awk '{print $2}'`"
#less $tmp
max=${#containers[@]}
echo "Account: $account"
for ((i=0;i<max;i++)); do
echo -ne "Container: ${containers[$i]}"
start="Container\s+${containers[$i]}"
((i<$max-1)) && end="Container\s+${containers[$((i+1))]}$" || end='__EOF__'
cat $tmp| grep -v Handoff| egrep 'Account|Container|Server:Port|__EOF__'| sed -r 's/Server:Port\s+Device\s+(.+)/\1/g'| \
sed -rn "/$start/{:a;N;/$end/!ba;s/$start|$end//g;s/^\n//g;p}"| eval $hostinfo_sedexpr| eval $devinfo_sedexpr| sort -k 1
echo ""
done
rm $tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment