Skip to content

Commit

Permalink
fetch metrics api added
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish Saha authored and Anish Saha committed Dec 4, 2021
1 parent db8f54f commit f9e57dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/routers/odin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from models.deployRequest import DeployRequest
from models.rollbackRequest import RollbackRequest
from util.utilityHelpers import Utils
from util.kubernetes import Kubernentes
import etcd3

router = APIRouter()
Expand Down Expand Up @@ -106,3 +107,20 @@ async def get_all_services():
except Exception as ex:
raise HTTPException(
status_code=500, detail="Failed to fetch all services: " + str(ex))

@router.get("/odin/metrics/{pod_name}", tags=["odin"])
async def get_pod_metrics(pod_name):
try:
metrics_params = Kubernentes.getPodMetrics(podName=pod_name).split()
return {
"status": "200",
"metadata": {
"name": metrics_params[3],
"cpu": metrics_params[4],
"memory": metrics_params[5]
}
}
except Exception as ex:
raise HTTPException(
status_code=500, details="Error getting metrics: " + str(ex)
)
5 changes: 5 additions & 0 deletions api/util/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ def getAllServices():
def getService(serviceName):
getService = "kubectl get services {serviceName} -o json".format(serviceName=serviceName)
return Utils.executeCommand(getService)

@staticmethod
def getPodMetrics(podName):
metricsCommand = "kubectl top pod {podName}".format(podName=podName)
return Utils.executeCommand(metricsCommand)

0 comments on commit f9e57dc

Please sign in to comment.