export TARGET_CLUSTER=クラスタ名
export AWS_XXXX = ...
pip install boto3
python3 ecs_cpu_analyzer.py | sort -n
Last active
September 28, 2018 07:54
-
-
Save pistatium/332611afa4f9533bfeaf95a1d84c3291 to your computer and use it in GitHub Desktop.
ECSクラスタのCPU予約量をタスクごとに集計するやーつ
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
import os | |
import boto3 | |
from collections import defaultdict | |
CLUSTER = os.environ.get('TARGET_CLUSTER') | |
ecs = boto3.client('ecs') | |
token = '' | |
cpus = defaultdict(int) | |
while True: | |
res = ecs.list_tasks(cluster=CLUSTER, desiredStatus='RUNNING', maxResults=100, launchType='EC2', nextToken=token) | |
tasks = res['taskArns'] | |
tasks = ecs.describe_tasks(cluster=CLUSTER, tasks=tasks) | |
for t in tasks['tasks']: | |
cpus[t['taskDefinitionArn'].split('/')[-1]] += int(t['cpu']) | |
token = res.get('nextToken') | |
if not token: | |
break | |
for name, cpu in cpus.items(): | |
print(f'{cpu} {name}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment