Merge pull request #1552 from benphelps/fix/issue-1415

Fix: Handle k8s widget metrics call fails
pull/1554/head
shamoon 2 years ago committed by GitHub
commit 8673548c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,18 +52,25 @@ export default async function handler(req, res) {
memTotal += mem;
});
const nodeMetrics = await metricsApi.getNodeMetrics();
nodeMetrics.items.forEach((nodeMetric) => {
const cpu = parseCpu(nodeMetric.usage.cpu);
const mem = parseMemory(nodeMetric.usage.memory);
cpuUsage += cpu;
memUsage += mem;
nodeMap[nodeMetric.metadata.name].cpu.load = cpu;
nodeMap[nodeMetric.metadata.name].cpu.percent = (cpu / nodeMap[nodeMetric.metadata.name].cpu.total) * 100;
nodeMap[nodeMetric.metadata.name].memory.used = mem;
nodeMap[nodeMetric.metadata.name].memory.free = nodeMap[nodeMetric.metadata.name].memory.total - mem;
nodeMap[nodeMetric.metadata.name].memory.percent = (mem / nodeMap[nodeMetric.metadata.name].memory.total) * 100;
});
try {
const nodeMetrics = await metricsApi.getNodeMetrics();
nodeMetrics.items.forEach((nodeMetric) => {
const cpu = parseCpu(nodeMetric.usage.cpu);
const mem = parseMemory(nodeMetric.usage.memory);
cpuUsage += cpu;
memUsage += mem;
nodeMap[nodeMetric.metadata.name].cpu.load = cpu;
nodeMap[nodeMetric.metadata.name].cpu.percent = (cpu / nodeMap[nodeMetric.metadata.name].cpu.total) * 100;
nodeMap[nodeMetric.metadata.name].memory.used = mem;
nodeMap[nodeMetric.metadata.name].memory.free = nodeMap[nodeMetric.metadata.name].memory.total - mem;
nodeMap[nodeMetric.metadata.name].memory.percent = (mem / nodeMap[nodeMetric.metadata.name].memory.total) * 100;
});
} catch (error) {
logger.error("Error getting metrics, ensure you have metrics-server installed: s", JSON.stringify(error));
return res.status(500).send({
error: "Error getting metrics, check logs for more details"
});
}
const cluster = {
cpu: {

Loading…
Cancel
Save