Created
January 13, 2023 10:35
-
-
Save kovetskiy/66f43bf6b5322e725644abed4dced0dd 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/python | |
# vim: ft=python | |
import fileinput | |
import sys | |
pods = open(sys.argv[1], 'r').readlines() | |
cluster_nodes = open(sys.argv[2], 'r').readlines() | |
def get_label(name): | |
for line in cluster_nodes: | |
if name not in line: | |
continue | |
if 'size=m5_2xlarge' in line: | |
return 'db-cache-proxy' | |
if 'type=other' in line: | |
return 'other' | |
if 'type=DB' in line: | |
return 'db' | |
if 'type=kafka' in line: | |
return 'kafka' | |
nodes = {} | |
for line in pods: | |
chunks = line.split('|') | |
pod = chunks[0].strip() | |
node = chunks[1].strip() | |
request = chunks[2].strip() | |
if not request: | |
continue | |
if 'm' in request: | |
request = request.replace('m', '') | |
request = float(request) / 1000 | |
else: | |
request = float(request) | |
pod = str(request) + " " + pod | |
if node not in nodes: | |
nodes[node] = { 'cpu': request, 'label': get_label(node), 'pods': [pod] } | |
else: | |
nodes[node]['cpu'] += request | |
nodes[node]['pods'].append(pod) | |
for name in nodes: | |
node = nodes[name] | |
print("node: ng-" + node['label'] + " " + name) | |
print("Requested: "+str(node['cpu'])) | |
print("Pods: ") | |
for pod in node['pods']: | |
print(" " + pod) | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment