-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.sh
executable file
·26 lines (23 loc) · 2.54 KB
/
metrics.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
instanceID=$(curl --silent http://169.254.169.254/latest/meta-data/instance-id)
region=$(hostname | cut -f 2 -d '.')
groupName=$(aws ec2 describe-instances --region $region --instance-id $instanceID | grep -B1 "aws:autoscaling:groupName" | sed -n '1p' | awk {'print $2'} | sed 's/"//g; s/,//g')
CPURequestUsage=$(kubectl describe node $(hostname) | grep cpu | sed '$!d' | awk {'print $3'} | sed 's/(//; s/%)//')
CPULimitUsage=$(kubectl describe node $(hostname) | grep cpu | sed '$!d' | awk {'print $5'} | sed 's/(//; s/%)//')
MemoryRequestUsage=$(kubectl describe node $(hostname) | grep memory | sed '$!d' | awk {'print $3'} | sed 's/(//; s/%)//')
MemoryLimitUsage=$(kubectl describe node $(hostname) | grep memory | sed '$!d' | awk {'print $5'} | sed 's/(//; s/%)//')
counter=0
for pod in $(kubectl get pods | grep -v NAME | awk {'print $1'}); do
if [[ $(kubectl describe pod $pod | grep "PodScheduled" | awk {'print $2'}) == "False" ]]; then
counter=$((counter+1))
fi
done
aws cloudwatch put-metric-data --namespace EKS --metric-name UnscheduledPods --value $counter --dimensions AutoScalingGroup=$groupName --region $region --unit Count
aws cloudwatch put-metric-data --namespace EKS --metric-name K8sCPUReservedRequests --value $CPURequestUsage --dimensions AutoScalingGroup=$groupName --region $region --unit Percent
aws cloudwatch put-metric-data --namespace EKS --metric-name K8sCPUReservedLimit --value $CPULimitUsage --dimensions AutoScalingGroup=$groupName --region $region --unit Percent
aws cloudwatch put-metric-data --namespace EKS --metric-name K8sMemoryReservedRequests --value $MemoryRequestUsage --dimensions AutoScalingGroup=$groupName --region $region --unit Percent
aws cloudwatch put-metric-data --namespace EKS --metric-name K8sMemoryReservedLimit --value $MemoryLimitUsage --dimensions AutoScalingGroup=$groupName --region $region --unit Percent
aws cloudwatch put-metric-data --namespace EKS --metric-name K8sCPUReservedRequests --value $CPURequestUsage --dimensions InstanceId=$instanceID --region $region --unit Percent
aws cloudwatch put-metric-data --namespace EKS --metric-name K8sCPUReservedLimit --value $CPULimitUsage --dimensions InstanceId=$instanceID --region $region --unit Percent
aws cloudwatch put-metric-data --namespace EKS --metric-name K8sMemoryReservedRequests --value $MemoryRequestUsage --dimensions InstanceId=$instanceID --region $region --unit Percent
aws cloudwatch put-metric-data --namespace EKS --metric-name K8sMemoryReservedLimit --value $MemoryLimitUsage --dimensions InstanceId=$instanceID --region $region --unit Percent