mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 23:38:46 +00:00
Kubernetes support
* Total CPU and Memory usage for the entire cluster * Total CPU and Memory usage for kubernetes pods * Service discovery via annotations on ingress * No storage stats yet * No network stats yet
This commit is contained in:
parent
b25ba09e18
commit
c4333fd2dc
18 changed files with 479 additions and 19 deletions
47
src/utils/kubernetes/kubernetes-utils.js
Normal file
47
src/utils/kubernetes/kubernetes-utils.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
export function parseCpu(cpuStr) {
|
||||
const unitLength = 1;
|
||||
const base = Number.parseInt(cpuStr, 10);
|
||||
const units = cpuStr.substring(cpuStr.length - unitLength);
|
||||
// console.log(Number.isNaN(Number(units)), cpuStr, base, units);
|
||||
if (Number.isNaN(Number(units))) {
|
||||
switch (units) {
|
||||
case 'n':
|
||||
return base / 1000000000;
|
||||
case 'u':
|
||||
return base / 1000000;
|
||||
case 'm':
|
||||
return base / 1000;
|
||||
default:
|
||||
return base;
|
||||
}
|
||||
} else {
|
||||
return Number.parseInt(cpuStr, 10);
|
||||
}
|
||||
}
|
||||
|
||||
export function parseMemory(memStr) {
|
||||
const unitLength = (memStr.substring(memStr.length - 1) === 'i' ? 2 : 1);
|
||||
const base = Number.parseInt(memStr, 10);
|
||||
const units = memStr.substring(memStr.length - unitLength);
|
||||
// console.log(Number.isNaN(Number(units)), memStr, base, units);
|
||||
if (Number.isNaN(Number(units))) {
|
||||
switch (units) {
|
||||
case 'Ki':
|
||||
return base * 1000;
|
||||
case 'K':
|
||||
return base * 1024;
|
||||
case 'Mi':
|
||||
return base * 1000000;
|
||||
case 'M':
|
||||
return base * 1024 * 1024;
|
||||
case 'Gi':
|
||||
return base * 1000000000;
|
||||
case 'G':
|
||||
return base * 1024 * 1024 * 1024;
|
||||
default:
|
||||
return base;
|
||||
}
|
||||
} else {
|
||||
return Number.parseInt(memStr, 10);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue