Skip to content

Instantly share code, notes, and snippets.

@dosaboy
Last active March 28, 2019 16:11
Show Gist options
  • Select an option

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

Select an option

Save dosaboy/bcfb807e286e682bd2b0c5c9c8b46762 to your computer and use it in GitHub Desktop.
#!/bin/bash -eu
#
# Origin: https://gist.github.com/dosaboy/bcfb807e286e682bd2b0c5c9c8b46762
#
# Authors:
# - [email protected]
# - [email protected]
#
# This must be executed on a node that has access to the Openstack apis.
#
# You must source your credentials before running this script.
#
# Returns average read and write iops used by the vm during the period
# specified.
(($#>=2)) || \
{ echo "Usage: `basename $0` <vm uuid> <block device name> [<num samples>]";
exit 1; }
server=$1
device=$2
samples=${3:-300}
# Required deps
for dep in jq bc curl; do
dpkg -s $dep| grep -q "Status: install ok installed" || \
sudo apt install -y $dep
done
echo "Authenticating"
token=`openstack token issue| grep ' id '| awk '{print $4}'`
echo "Fetching api info"
svcs=`curl -s -H "X-Auth-Token: $token" "${OS_AUTH_URL}/services"`
eps=`curl -s -H "X-Auth-Token: $token" "${OS_AUTH_URL}/endpoints"`
get_svc ()
{
python << EOF
import json
ss = json.loads('$svcs')['services']
print [s['id'] for s in ss if s['name'] == "$1"][0]
EOF
}
get_ep ()
{
python << EOF
import json
ss = json.loads('$eps')['endpoints']
print [s['url'] for s in ss if s['service_id'] == "$1" and s['interface'] == 'admin'][0]
EOF
}
nova_svc=`get_svc nova`
nova_ep=`get_ep $nova_svc| sed -r 's,(.+/v[0-9\.]+)/.+,\1,g'`
fdiagnostics=`mktemp`
fread_req=`mktemp`
fwrite_req=`mktemp`
cleanup () { rm -f $fdiagnostics $fread_req $fwrite_req; }
trap cleanup EXIT INT
get_server_dev_iops ()
{
server=$1
dev=$2
rd_peak=0
wr_peak=0
echo "Calculating average IOPS for server '$server' device '$dev' using $samples 1s samples"
for ((i=0;i<$samples;i++)); do
echo -n "."
curl -s -H "X-Auth-Token: $token" $nova_ep/servers/$server/diagnostics > $fdiagnostics
rd_iops=`jq -r ".${dev}_read_req" $fdiagnostics`
wr_iops=`jq -r ".${dev}_write_req" $fdiagnostics`
sleep 1
curl -s -H "X-Auth-Token: $token" $nova_ep/servers/$server/diagnostics > $fdiagnostics
rd_iops2=`jq -r ".${dev}_read_req" $fdiagnostics`
wr_iops2=`jq -r ".${dev}_write_req" $fdiagnostics`
delta=$((rd_iops2-rd_iops))
((delta > rd_peak)) && rd_peak=$delta
echo $delta >> $fread_req
delta=$((wr_iops2-wr_iops))
((delta > wr_peak)) && wr_peak=$delta
echo $delta >> $fwrite_req
done
echo -e "\nResults:"
sum=`paste -sd+ $fread_req | bc`
echo "rd_iops: peak=$rd_peak avg=$((sum/$samples))"
sum=`paste -sd+ $fwrite_req | bc`
echo "wr_iops: peak=$wr_peak avg=$((sum/$samples))"
}
get_server_dev_iops $server $device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment