mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 23:38:46 +00:00
new status format, new podSelector field, more accurate pod stats
* renamed pod label prefix from "homepage" to "gethomepage.dev" which is more inline with typical kubernetes practices
This commit is contained in:
parent
174cb651b4
commit
09eb172079
8 changed files with 65 additions and 40 deletions
|
@ -8,7 +8,7 @@ const logger = createLogger("kubernetesStatsService");
|
|||
|
||||
export default async function handler(req, res) {
|
||||
const APP_LABEL = "app.kubernetes.io/name";
|
||||
const { service } = req.query;
|
||||
const { service, podSelector } = req.query;
|
||||
|
||||
const [namespace, appName] = service;
|
||||
if (!namespace && !appName) {
|
||||
|
@ -17,7 +17,7 @@ export default async function handler(req, res) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
const labelSelector = `${APP_LABEL}=${appName}`;
|
||||
const labelSelector = podSelector !== undefined ? podSelector : `${APP_LABEL}=${appName}`;
|
||||
|
||||
try {
|
||||
const kc = getKubeConfig();
|
||||
|
@ -63,7 +63,7 @@ export default async function handler(req, res) {
|
|||
});
|
||||
});
|
||||
|
||||
const stats = await pods.map(async (pod) => {
|
||||
const podStatsList = await Promise.all(pods.map(async (pod) => {
|
||||
let depMem = 0;
|
||||
let depCpu = 0;
|
||||
const podMetrics = await metricsApi.getPodMetrics(namespace, pod.metadata.name)
|
||||
|
@ -85,13 +85,15 @@ export default async function handler(req, res) {
|
|||
mem: depMem,
|
||||
cpu: depCpu
|
||||
};
|
||||
}).reduce(async (finalStats, podStatPromise) => {
|
||||
const podStats = await podStatPromise;
|
||||
return {
|
||||
mem: finalStats.mem + podStats.mem,
|
||||
cpu: finalStats.cpu + podStats.cpu
|
||||
};
|
||||
});
|
||||
}));
|
||||
const stats = {
|
||||
mem: 0,
|
||||
cpu: 0
|
||||
}
|
||||
podStatsList.forEach((podStat) => {
|
||||
stats.mem += podStat.mem;
|
||||
stats.cpu += podStat.cpu;
|
||||
});
|
||||
stats.cpuLimit = cpuLimit;
|
||||
stats.memLimit = memLimit;
|
||||
stats.cpuUsage = cpuLimit ? stats.cpu / cpuLimit : 0;
|
||||
|
|
|
@ -7,7 +7,7 @@ const logger = createLogger("kubernetesStatusService");
|
|||
|
||||
export default async function handler(req, res) {
|
||||
const APP_LABEL = "app.kubernetes.io/name";
|
||||
const { service } = req.query;
|
||||
const { service, podSelector } = req.query;
|
||||
|
||||
const [namespace, appName] = service;
|
||||
if (!namespace && !appName) {
|
||||
|
@ -16,8 +16,8 @@ export default async function handler(req, res) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
const labelSelector = `${APP_LABEL}=${appName}`;
|
||||
|
||||
const labelSelector = podSelector !== undefined ? podSelector : `${APP_LABEL}=${appName}`;
|
||||
logger.info("labelSelector %s/%s = %s", namespace, appName, labelSelector);
|
||||
try {
|
||||
const kc = getKubeConfig();
|
||||
if (!kc) {
|
||||
|
@ -47,10 +47,14 @@ export default async function handler(req, res) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// at least one pod must be in the "Running" phase, otherwise its "down"
|
||||
const runningPod = pods.find(pod => pod.status.phase === "Running");
|
||||
const status = runningPod ? "running" : "down";
|
||||
const someReady = pods.find(pod => pod.status.phase === "Running");
|
||||
const allReady = pods.every((pod) => pod.status.phase === "Running");
|
||||
let status = "down";
|
||||
if (allReady) {
|
||||
status = "running";
|
||||
} else if (someReady) {
|
||||
status = "partial";
|
||||
}
|
||||
res.status(200).json({
|
||||
status
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue