Created
March 31, 2021 17:37
-
-
Save cdalar/f5749040ccb7487203738a134767e3fc to your computer and use it in GitHub Desktop.
Enabling Group Metrics Collection for NodeGroup of AWS EKS and Capacity Alarm.
This file contains 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
# Get's the FIRST Cluster on list-clusters. Assuming you only have 1 EKS | |
EKS_CLUSTER_NAME=$(aws eks list-clusters --region=eu-central-1 | jq -r .clusters[0]) | |
echo $EKS_CLUSTER_NAME | |
# First NodeGroup from the list. | |
NG=$(aws eks list-nodegroups --cluster-name $EKS_CLUSTER_NAME | jq -r '.nodegroups[0]') | |
echo $NG | |
# First Autoscaling Group Name | |
ASG_NAME=$(aws eks describe-nodegroup --cluster-name $EKS_CLUSTER_NAME --nodegroup-name $NG | jq -r '.nodegroup.resources.autoScalingGroups[0].name') | |
# Enable Autoscaling Group Metrics | |
aws autoscaling enable-metrics-collection --auto-scaling-group-name $ASG_NAME --granularity "1Minute" | |
# --------- Extra ---------- | |
# Get SNS Topic ARN for Alarms. | |
SNS_ARN=$(aws sns list-topics | jq -r '.Topics[0].TopicArn') | |
# EKS Autoscaling Capacity Alarm | |
EKS_ASG_MAX_SIZE=$(aws cloudformation describe-stacks | jq -r --arg EKS_CLUSTER_NAME "$EKS_CLUSTER_NAME" '.Stacks[] | select( .StackName == $EKS_CLUSTER_NAME+"-eks-nodegroup")' | jq -r '.Parameters[] | select(.ParameterKey == "EksAsgMaxSize") | .ParameterValue') | |
aws cloudwatch put-metric-alarm --alarm-name "${EKS_CLUSTER_NAME}-EKS NodeGroup EksAsgCapacityAlarm" --evaluation-periods 1 --comparison-operator GreaterThanOrEqualToThreshold --metric-name GroupTotalInstances --period 600 --namespace AWS/AutoScaling --statistic Maximum --threshold $EKS_ASG_MAX_SIZE --dimensions Name=AutoScalingGroupName,Value=$ASG_NAME --ok-actions $SNS_ARN --alarm-actions $SNS_ARN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment