mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 08:20:58 +00:00 
			
		
		
		
	Handle k8s widget metrics call fails
This commit is contained in:
		
							parent
							
								
									2bbe5b04c7
								
							
						
					
					
						commit
						bd5c10e907
					
				@ -52,18 +52,25 @@ export default async function handler(req, res) {
 | 
				
			|||||||
      memTotal += mem;
 | 
					      memTotal += mem;
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const nodeMetrics = await metricsApi.getNodeMetrics();
 | 
					    try {
 | 
				
			||||||
    nodeMetrics.items.forEach((nodeMetric) => {
 | 
					      const nodeMetrics = await metricsApi.getNodeMetrics();
 | 
				
			||||||
      const cpu = parseCpu(nodeMetric.usage.cpu);
 | 
					      nodeMetrics.items.forEach((nodeMetric) => {
 | 
				
			||||||
      const mem = parseMemory(nodeMetric.usage.memory);
 | 
					        const cpu = parseCpu(nodeMetric.usage.cpu);
 | 
				
			||||||
      cpuUsage += cpu;
 | 
					        const mem = parseMemory(nodeMetric.usage.memory);
 | 
				
			||||||
      memUsage += mem;
 | 
					        cpuUsage += cpu;
 | 
				
			||||||
      nodeMap[nodeMetric.metadata.name].cpu.load = cpu;
 | 
					        memUsage += mem;
 | 
				
			||||||
      nodeMap[nodeMetric.metadata.name].cpu.percent = (cpu / nodeMap[nodeMetric.metadata.name].cpu.total) * 100;
 | 
					        nodeMap[nodeMetric.metadata.name].cpu.load = cpu;
 | 
				
			||||||
      nodeMap[nodeMetric.metadata.name].memory.used = mem;
 | 
					        nodeMap[nodeMetric.metadata.name].cpu.percent = (cpu / nodeMap[nodeMetric.metadata.name].cpu.total) * 100;
 | 
				
			||||||
      nodeMap[nodeMetric.metadata.name].memory.free = nodeMap[nodeMetric.metadata.name].memory.total - mem;
 | 
					        nodeMap[nodeMetric.metadata.name].memory.used = mem;
 | 
				
			||||||
      nodeMap[nodeMetric.metadata.name].memory.percent = (mem / nodeMap[nodeMetric.metadata.name].memory.total) * 100;
 | 
					        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 = {
 | 
					    const cluster = {
 | 
				
			||||||
      cpu: {
 | 
					      cpu: {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user