Last active
January 4, 2016 06:09
-
-
Save sechiro/8580142 to your computer and use it in GitHub Desktop.
aws cliを使ってCPU使用率(もしくは第一引数で指定したMetric)の平均値を確認。jqを入れているのは、タイムスタンプ順にソートするため。スクリプト中の"instance_id"には自分のインスタンスのIDを入れてください。
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 | |
namespace=AWS/EC2 | |
instance_id=i-a63f41a3 | |
os_name=`uname` | |
now=`date -u "+%Y-%m-%dT%H:%M:%SZ"` | |
if [ $os_name = "Darwin" ]; then | |
yesterday=`date -u -v-1d "+%Y-%m-%dT%H:%M:%SZ"` | |
else | |
yesterday=`date -u -d "1 days ago" "+%Y-%m-%dT%H:%M:%SZ"` | |
fi | |
start_time=${2:-$yesterday} | |
end_time=${3:-$now} | |
period=300 | |
metric=${1:-CPUUtilization} | |
aws cloudwatch get-metric-statistics \ | |
--namespace $namespace \ | |
--metric-name $metric \ | |
--start-time $start_time \ | |
--end-time $end_time \ | |
--period $period \ | |
--statistics "Average" \ | |
--dimensions Name=InstanceId,Value=$instance_id | jq '.Datapoints | sort_by(.Timestamp)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment