Skip to content

Instantly share code, notes, and snippets.

@sechiro
Created January 6, 2015 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sechiro/9ea07d44b0c33d0afbf2 to your computer and use it in GitHub Desktop.
Save sechiro/9ea07d44b0c33d0afbf2 to your computer and use it in GitHub Desktop.
aws cloudwatch list-metricsの出力結果に対し、aws cloudwatch get-metric-statisticsを実行する
#!/bin/bash
if [ `uname` = "Darwin" ]; then
start_time=`date -u -v-30M "+%Y-%m-%dT%H:%M:%SZ"`
else
start_time=`date -u -d "30 minute ago" "+%Y-%m-%dT%H:%M:%SZ"`
fi
end_time=`date -u "+%Y-%m-%dT%H:%M:%SZ"`
period=300
statistics=Average
args_list=`aws cloudwatch list-metrics | jq -r '.Metrics[] | "--namespace " + .Namespace + " --metric-name " + .MetricName + " --dimensions " + ( .Dimensions[] | "Name=" + .Name + ",Value=" + .Value)'`
echo "$args_list" | while read line
do
aws cloudwatch get-metric-statistics $line \
--start-time $start_time \
--end-time $end_time \
--period $period \
--statistics $statistics
done
# 最新データを取りたい場合は以下でフィルタ
# jq '.Datapoints | sort_by(.Timestamp) | reverse| .[0]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment