Skip to content

Instantly share code, notes, and snippets.

@rjz
Last active May 8, 2017 16:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjz/f4784730ed13943218a382a030bc85cd to your computer and use it in GitHub Desktop.
Save rjz/f4784730ed13943218a382a030bc85cd to your computer and use it in GitHub Desktop.
Dump dynamo consumption high-water marks from cloudwatch
#!/bin/bash
# Usage:
#
# $ metrics.sh > dynamo_tables.txt
#
# $ cat dynamo_tables.txt \
# | tr : ' ' \
# | sed 's/\./ /' \
# | sed 's/ =//' \
# | column -s' ' -t
METRICS=(
'ConsumedReadCapacityUnits'
'ConsumedWriteCapacityUnits'
)
days_ago() {
local day_count=$1
date -ju -v-${day_count}d +'%Y-%m-%dT%H:%M:%SZ'
}
NOW=$(days_ago 0)
CW_NAMESPACE=AWS/DynamoDB
raw_cw() {
local dims=$1
local metric=$2
aws cloudwatch get-metric-statistics \
--namespace=$CW_NAMESPACE \
--period=1200 \
--start-time=$(days_ago 14) \
--end-time=$NOW \
--dimensions ${dims} \
--metric-name=${metric} \
--statistics Maximum
}
cw() {
raw_cw "$1" "$2" \
| jq '.Datapoints | map(.Maximum) | max'
}
list_indexes() {
local table=$1
aws dynamodb describe-table \
--table-name=${table} \
| jq -r '.Table | .GlobalSecondaryIndexes[] | .IndexName'
}
# Filter $TABLES as needed!
TABLES=$(aws dynamodb list-tables \
| jq -r '.TableNames[] | @text'
)
for t in $TABLES; do
tis=$(list_indexes $t)
for m in ${METRICS[@]}; do
echo "$t:__table__.$m = $(cw "Name=TableName,Value=${t}" ${m})"
for i in $tis; do
echo "$t:$i.$m = $(cw "Name=TableName,Value=${t} Name=GlobalSecondaryIndexName,Value=${i}" ${m})"
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment