fix(ui): return namespaces
This commit is contained in:
@@ -155,6 +155,41 @@ def fetch_ai_summary():
|
||||
except requests.RequestException as e:
|
||||
return f"An error occurred while fetching the summary: {str(e)}"
|
||||
|
||||
def display_namespace_usage():
|
||||
config.load_incluster_config()
|
||||
metrics_client = client.CustomObjectsApi()
|
||||
|
||||
table = Table(title="📊 Namespace Resource Usage", style="bold magenta")
|
||||
table.add_column("Namespace", style="white")
|
||||
table.add_column("CPU (Cores)", justify="right", style="yellow")
|
||||
table.add_column("Memory (MiB)", justify="right", style="cyan")
|
||||
|
||||
namespace_usage = {}
|
||||
pod_metrics = metrics_client.list_cluster_custom_object(
|
||||
group="metrics.k8s.io", version="v1beta1", plural="pods"
|
||||
)
|
||||
|
||||
for pod in pod_metrics["items"]:
|
||||
namespace = pod["metadata"]["namespace"]
|
||||
if namespace not in namespace_usage:
|
||||
namespace_usage[namespace] = {"cpu": 0, "memory": 0}
|
||||
|
||||
for container in pod["containers"]:
|
||||
cpu_usage = container["usage"]["cpu"]
|
||||
memory_usage = container["usage"]["memory"]
|
||||
|
||||
namespace_usage[namespace]["cpu"] += convert_cpu_to_cores(cpu_usage)
|
||||
namespace_usage[namespace]["memory"] += convert_memory_to_mib(memory_usage)
|
||||
|
||||
for namespace, usage in namespace_usage.items():
|
||||
table.add_row(
|
||||
namespace,
|
||||
f"{round(usage['cpu'], 4)}",
|
||||
f"{round(usage['memory'], 2)}"
|
||||
)
|
||||
|
||||
console.print(table)
|
||||
|
||||
def display_ai_summary():
|
||||
summary = fetch_ai_summary()
|
||||
console.print("\n[bold magenta]AI Summary of Kubernetes Cluster:[/bold magenta]")
|
||||
|
||||
Reference in New Issue
Block a user