mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-09 18:02:08 +08:00
Run pre-commit hooks over existing codebase
Co-Authored-By: Ben Phelps <ben@phelps.io>
This commit is contained in:
@@ -13,7 +13,7 @@ export default async function handler(req, res) {
|
||||
const [namespace, appName] = service;
|
||||
if (!namespace && !appName) {
|
||||
res.status(400).send({
|
||||
error: "kubernetes query parameters are required"
|
||||
error: "kubernetes query parameters are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -23,13 +23,14 @@ export default async function handler(req, res) {
|
||||
const kc = getKubeConfig();
|
||||
if (!kc) {
|
||||
res.status(500).send({
|
||||
error: "No kubernetes configuration"
|
||||
error: "No kubernetes configuration",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const coreApi = kc.makeApiClient(CoreV1Api);
|
||||
const metricsApi = new Metrics(kc);
|
||||
const podsResponse = await coreApi.listNamespacedPod(namespace, null, null, null, null, labelSelector)
|
||||
const podsResponse = await coreApi
|
||||
.listNamespacedPod(namespace, null, null, null, null, labelSelector)
|
||||
.then((response) => response.body)
|
||||
.catch((err) => {
|
||||
logger.error("Error getting pods: %d %s %s", err.statusCode, err.body, err.response);
|
||||
@@ -37,7 +38,7 @@ export default async function handler(req, res) {
|
||||
});
|
||||
if (!podsResponse) {
|
||||
res.status(500).send({
|
||||
error: "Error communicating with kubernetes"
|
||||
error: "Error communicating with kubernetes",
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -63,33 +64,36 @@ export default async function handler(req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
const podStatsList = await Promise.all(pods.map(async (pod) => {
|
||||
let depMem = 0;
|
||||
let depCpu = 0;
|
||||
const podMetrics = await metricsApi.getPodMetrics(namespace, pod.metadata.name)
|
||||
.then((response) => response)
|
||||
.catch((err) => {
|
||||
// 404 generally means that the metrics have not been populated yet
|
||||
if (err.statusCode !== 404) {
|
||||
logger.error("Error getting pod metrics: %d %s %s", err.statusCode, err.body, err.response);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if (podMetrics) {
|
||||
podMetrics.containers.forEach((container) => {
|
||||
depMem += parseMemory(container.usage.memory);
|
||||
depCpu += parseCpu(container.usage.cpu);
|
||||
});
|
||||
}
|
||||
return {
|
||||
mem: depMem,
|
||||
cpu: depCpu
|
||||
};
|
||||
}));
|
||||
const podStatsList = await Promise.all(
|
||||
pods.map(async (pod) => {
|
||||
let depMem = 0;
|
||||
let depCpu = 0;
|
||||
const podMetrics = await metricsApi
|
||||
.getPodMetrics(namespace, pod.metadata.name)
|
||||
.then((response) => response)
|
||||
.catch((err) => {
|
||||
// 404 generally means that the metrics have not been populated yet
|
||||
if (err.statusCode !== 404) {
|
||||
logger.error("Error getting pod metrics: %d %s %s", err.statusCode, err.body, err.response);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if (podMetrics) {
|
||||
podMetrics.containers.forEach((container) => {
|
||||
depMem += parseMemory(container.usage.memory);
|
||||
depCpu += parseCpu(container.usage.cpu);
|
||||
});
|
||||
}
|
||||
return {
|
||||
mem: depMem,
|
||||
cpu: depCpu,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const stats = {
|
||||
mem: 0,
|
||||
cpu: 0
|
||||
}
|
||||
cpu: 0,
|
||||
};
|
||||
podStatsList.forEach((podStat) => {
|
||||
stats.mem += podStat.mem;
|
||||
stats.cpu += podStat.cpu;
|
||||
@@ -99,12 +103,12 @@ export default async function handler(req, res) {
|
||||
stats.cpuUsage = cpuLimit ? stats.cpu / cpuLimit : 0;
|
||||
stats.memUsage = memLimit ? stats.mem / memLimit : 0;
|
||||
res.status(200).json({
|
||||
stats
|
||||
stats,
|
||||
});
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
res.status(500).send({
|
||||
error: "unknown error"
|
||||
error: "unknown error",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user