-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathecs-cluster.10m.sh
executable file
·55 lines (44 loc) · 2.26 KB
/
ecs-cluster.10m.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# <bitbar.title>Amazon ECS Cluster Status</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Bob Zoller</bitbar.author>
# <bitbar.author.github>bobzoller</bitbar.author.github>
# <bitbar.desc>Shows statistics about your Amazon ECS cluster.</bitbar.desc>
# <bitbar.dependencies>awscli,jq</bitbar.dependencies>
# Dependencies:
# awscli (https://aws.amazon.com/cli/)
# jq (https://stedolan.github.io/jq/)
AWS_CLI_PROFILE="default"
ECS_CLUSTER=""
export PATH="$PATH:/usr/local/bin"
if [ -z "$ECS_CLUSTER" ]; then
echo "Missing configuration: cluster name"
exit 1
fi
data=$( aws --profile $AWS_CLI_PROFILE ecs list-container-instances --output json --cluster $ECS_CLUSTER )
instance_ids=$( echo "$data" | jq -r '.containerInstanceArns | map(. | split("/") | last) | join(" ")' )
data=$( aws --profile $AWS_CLI_PROFILE ecs describe-container-instances --output json --cluster $ECS_CLUSTER --container-instances "$instance_ids" )
instance_count=$( echo "$data" | jq -r '.containerInstances | length' )
total_memory=$(( $( echo "$data" | jq -r '.containerInstances | map(.registeredResources[] | select(.name == "MEMORY") | .integerValue) | add' ) / 1000 ))
remaining_memory=$(( $( echo "$data" | jq -r '.containerInstances | map(.remainingResources[] | select(.name == "MEMORY") | .integerValue) | add' ) / 1000 ))
reserved_memory=$(( total_memory - remaining_memory ))
usage_memory=$( echo "$reserved_memory * 100 / $total_memory" | bc )
total_cpu=$( echo "$data" | jq -r '.containerInstances | map(.registeredResources[] | select(.name == "CPU") | .integerValue) | add' )
remaining_cpu=$( echo "$data" | jq -r '.containerInstances | map(.remainingResources[] | select(.name == "CPU") | .integerValue) | add' )
reserved_cpu=$(( total_cpu - remaining_cpu ))
usage_cpu=$( echo "$reserved_cpu * 100 / $total_cpu" | bc )
mono() {
echo "$1 | font=Monaco trim=false"
}
echo "#:${instance_count} C:${usage_cpu}% M:${usage_memory}%"
echo "---"
mono "Instances:"
mono " Count: ${instance_count}"
mono "Memory:"
mono " Total: ${total_memory} GB"
mono " Reserved: ${reserved_memory} GB"
mono " Free: ${remaining_memory} GB"
mono "CPU:"
mono " Total: ${total_cpu} shares"
mono " Reserved: ${reserved_cpu} shares"
mono " Free: ${remaining_cpu} shares"