Created
April 27, 2017 15:51
-
-
Save mago0/b4eef9c6c3cffb732a9c034de364921d to your computer and use it in GitHub Desktop.
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 | |
ENVIRONMENT=$1 | |
REGION=$2 | |
ELB=$3 | |
WORKERS=$4 | |
CURRENT_MINUTE=$(date -d now -u "+%M") | |
START_MINUTE=$(expr $(expr 60 + $CURRENT_MINUTE - 1) % 60) | |
START_DATE=$(date -u "+%Y-%m-%dT%H:$START_MINUTE:%S") | |
END_DATE=$(date -u "+%Y-%m-%dT%H:%M:%S") | |
LATENCY=$(aws cloudwatch get-metric-statistics --region $REGION --namespace AWS/ELB --metric-name Latency --dimensions Name=LoadBalancerName,Value=$ELB --start-time $START_DATE --end-time $END_DATE --period 60 --statistics Average | jq ".Datapoints[0].Average") | |
REQUESTS=$(aws cloudwatch get-metric-statistics --region $REGION --namespace AWS/ELB --metric-name RequestCount --dimensions Name=LoadBalancerName,Value=$ELB --start-time $START_DATE --end-time $END_DATE --period 60 --statistics Sum | jq ".Datapoints[0].Sum") | |
NODES=$(aws cloudwatch get-metric-statistics --region $REGION --namespace AWS/ELB --metric-name HealthyHostCount --dimensions Name=LoadBalancerName,Value=$ELB --start-time $START_DATE --end-time $END_DATE --period 60 --statistics Average | jq ".Datapoints[0].Average") | |
WORKER_UTILIZATION="$(echo "($REQUESTS / 60 * $LATENCY)/($WORKERS * $NODES)" | bc -l)" | |
aws cloudwatch put-metric-data --region $REGION --namespace Tilt/ELB --metric-name WorkerUtilization --dimensions Name=$ELB,Env=$ENVIRONMENT --unit Percent --value $WORKER_UTILIZATION | |
echo $WORKER_UTILIZATION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment