mirror of
https://github.com/Rainyy21/k3s-health-dashboard.git
synced 2026-10-11 00:50:20 -04:00
finish the main code
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from fastapi import APIRouter
|
||||
from k8s_client import get_custom_client
|
||||
|
||||
router = APIRouter(prefix="/metrics", tags=["metrics"])
|
||||
|
||||
|
||||
@router.get("/nodes")
|
||||
def node_metrics():
|
||||
api = get_custom_client()
|
||||
try:
|
||||
data = api.list_cluster_custom_object(
|
||||
group="metrics.k8s.io", version="v1beta1", plural="nodes"
|
||||
)
|
||||
return [
|
||||
{
|
||||
"name": item["metadata"]["name"],
|
||||
"cpu_usage": item["usage"]["cpu"], # e.g. "250m"
|
||||
"memory_usage": item["usage"]["memory"], # e.g. "512Mi"
|
||||
}
|
||||
for item in data["items"]
|
||||
]
|
||||
except Exception as e:
|
||||
return {"error": str(e), "hint": "Is metrics-server installed?"}
|
||||
Reference in New Issue
Block a user