Created
January 6, 2015 16:00
-
-
Save sechiro/9ea07d44b0c33d0afbf2 to your computer and use it in GitHub Desktop.
aws cloudwatch list-metricsの出力結果に対し、aws cloudwatch get-metric-statisticsを実行する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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