Skip to content

Commit

Permalink
Update detection of underperorming pods
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclark5 committed Feb 10, 2025
1 parent c9cc4fa commit 20a1f9e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
14 changes: 12 additions & 2 deletions kubecustom/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,22 @@ def utilization_per_deployment(keep_key="", namespace=None, verbose=True):
try:
cpu_usage = (
100
* np.array([x["cpu"] for _, x in pod_info.items()])
* np.array(
[
x["cpu"] if x["cpu"] is not None else 0
for _, x in pod_info.items()
]
)
/ deployment_info[dep_name]["cpu"]
)
memory_usage = (
100
* np.array([x["memory"] for _, x in pod_info.items()])
* np.array(
[
x["memory"] if x["memory"] is not None else 0
for _, x in pod_info.items()
]
)
/ deployment_info[dep_name]["memory"]
)
output[dep_name] = {
Expand Down
15 changes: 15 additions & 0 deletions kubecustom/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ def get_pods_resource_info(
group, version = "metrics.k8s.io", "v1beta1"
resource = "pods"

pod_list = [pod.metadata.name for pod in get_pod_list(namespace=namespace)]
pod_metrics = api.list_namespaced_custom_object(group, version, namespace, resource)

# Process and display the metrics
output = defaultdict(dict)
for pod in pod_metrics["items"]:
pod_name = pod["metadata"]["name"]
pod_list.remove(pod_name)
if keep_key not in pod_name:
continue
containers = pod["containers"]
Expand All @@ -280,6 +282,19 @@ def get_pods_resource_info(
"labels": pod["metadata"]["labels"],
}

for pod_name in pod_list:
cpu_usage, memory_usage = None, None
if verbose:
print(
"Pod: {pod_name}, Container: None, CPU: None None,\tMemory: None None,\tLabels: None"
)

output[pod_name] = {
"cpu": cpu_usage,
"memory": memory_usage,
"labels": None,
}

return output


Expand Down

0 comments on commit 20a1f9e

Please sign in to comment.