-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added visual cpu and memory usage indicator to pod overview
- Loading branch information
Showing
17 changed files
with
410 additions
and
22 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<script setup lang="ts"> | ||
import { V1Pod, PodMetric } from "@kubernetes/client-node"; | ||
import { memoryParser } from "@/lib/unitParsers"; | ||
import PodUsageChartBar from "./PodUsageChartBar.vue"; | ||
import { | ||
Tooltip, | ||
TooltipContent, | ||
TooltipProvider, | ||
TooltipTrigger, | ||
} from "@/components/ui/tooltip"; | ||
const props = defineProps<{ | ||
pod: V1Pod & { metrics: PodMetric[] }; | ||
}>(); | ||
const cpuDatapoints = computed(() => { | ||
return props.pod.metrics.map((metric: PodMetric) => { | ||
return metric.containers.reduce((acc, container) => { | ||
return acc + Number(container.usage.cpu.replace("n", "")) / 1000000; | ||
}, 0); | ||
}); | ||
}); | ||
const memoryDatapoints = computed(() => { | ||
return props.pod.metrics.map((metric: PodMetric) => { | ||
return metric.containers.reduce((acc, container) => { | ||
return acc + Number(container.usage.memory.replace("Ki", "")) * 1000; | ||
}, 0); | ||
}); | ||
}); | ||
const latestCpuDatapoint = computed(() => { | ||
return cpuDatapoints.value.toReversed()[0]; | ||
}); | ||
const latestMemoryDatapoint = computed(() => { | ||
return memoryDatapoints.value.toReversed()[0]; | ||
}); | ||
const cpuRequest = computed(() => { | ||
return props.pod.spec.containers.reduce((acc, container) => { | ||
if (container.resources?.requests?.cpu === undefined) { | ||
return acc; | ||
} | ||
if (!container.resources?.requests?.cpu.includes("m")) { | ||
return acc + Number(container.resources?.requests?.cpu) * 1000; | ||
} | ||
return ( | ||
acc + Number(container.resources?.requests?.cpu?.replace("m", "") || 0) | ||
); | ||
}, 0); | ||
}); | ||
const memoryRequest = computed(() => { | ||
return props.pod.spec.containers.reduce((acc, container) => { | ||
if (container.resources?.requests?.memory === undefined) { | ||
return acc; | ||
} | ||
return acc + memoryParser(container.resources?.requests?.memory); | ||
return ( | ||
acc + Number(container.resources?.requests?.cpu?.replace("Mi", "") || 0) | ||
); | ||
}, 0); | ||
}); | ||
const cpuLimit = computed(() => { | ||
return props.pod.spec.containers.reduce((acc, container) => { | ||
if (container.resources?.limits?.cpu === undefined) { | ||
return acc; | ||
} | ||
if (!container.resources?.limits?.cpu.includes("m")) { | ||
return acc + Number(container.resources?.limits?.cpu) * 1000; | ||
} | ||
return ( | ||
acc + Number(container.resources?.limits?.cpu?.replace("m", "") || 0) | ||
); | ||
}, 0); | ||
}); | ||
const memoryLimit = computed(() => { | ||
return props.pod.spec.containers.reduce((acc, container) => { | ||
if (container.resources?.limits?.memory === undefined) { | ||
return acc; | ||
} | ||
return acc + memoryParser(container.resources?.limits?.memory); | ||
}, 0); | ||
}); | ||
const cpuUsage = computed(() => { | ||
return cpuLimit.value > 0 | ||
? (latestCpuDatapoint.value / cpuLimit.value) * 100 | ||
: 0; | ||
}); | ||
const memoryUsage = computed(() => { | ||
return memoryLimit.value > 0 | ||
? (latestMemoryDatapoint.value / memoryLimit.value) * 100 | ||
: 0; | ||
}); | ||
const cpuThreshold = computed(() => { | ||
return cpuLimit.value > 0 ? (cpuRequest.value / cpuLimit.value) * 100 : 0; | ||
}); | ||
const memoryThreshold = computed(() => { | ||
return memoryLimit.value > 0 | ||
? (memoryRequest.value / memoryLimit.value) * 100 | ||
: 0; | ||
}); | ||
</script> | ||
<template> | ||
<TooltipProvider :disable-hoverable-content="true"> | ||
<Tooltip :delay-duration="200"> | ||
<TooltipTrigger as-child> | ||
<div class="space-y-1"> | ||
<PodUsageChartBar | ||
v-if="cpuDatapoints" | ||
text="C" | ||
:value="cpuUsage" | ||
:threshold="cpuThreshold > 0 ? cpuThreshold : undefined" | ||
/> | ||
<PodUsageChartBar | ||
v-if="memoryDatapoints" | ||
text="M" | ||
:value="memoryUsage" | ||
:threshold="memoryThreshold > 0 ? memoryThreshold : undefined" | ||
/> | ||
</div> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
<div> | ||
<div class="font-bold">CPU</div> | ||
<div> | ||
U: {{ latestCpuDatapoint.toFixed(0) }}m / R: {{ cpuRequest }}m / L: | ||
{{ cpuLimit }}m | ||
</div> | ||
<div class="mt-2 font-bold">Memory</div> | ||
<div> | ||
U: {{ (latestMemoryDatapoint / 1000000).toFixed(0) }}Mi / R: | ||
{{ (memoryRequest / 1000000).toFixed(0) }} Mi / L: | ||
{{ (memoryLimit / 1000000).toFixed(0) }}Mi | ||
</div> | ||
</div> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script setup lang="ts"> | ||
defineProps<{ | ||
text: string; | ||
value: number; | ||
threshold?: number; | ||
}>(); | ||
</script> | ||
<template> | ||
<div> | ||
<div class="flex items-center space-x-2 text-xxs"> | ||
<span class="w-[10px] text-center leading-none">{{ text }}</span> | ||
<div class="relative w-full h-[5px] bg-gray-800"> | ||
<div | ||
class="w-0 h-[5px] bg-green-500" | ||
:class="{ | ||
'bg-red-500': value >= 90, | ||
'bg-yellow-500': value >= 70 && value < 90, | ||
}" | ||
:style="{ width: `${value}%` }" | ||
></div> | ||
<div | ||
v-if="threshold" | ||
class="absolute top-0 w-[1px] h-[5px] bg-white opacity-50" | ||
:style="{ left: `${threshold}%` }" | ||
></div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script setup lang="ts"> | ||
import { TooltipRoot, type TooltipRootEmits, type TooltipRootProps, useForwardPropsEmits } from 'radix-vue' | ||
const props = defineProps<TooltipRootProps>() | ||
const emits = defineEmits<TooltipRootEmits>() | ||
const forwarded = useForwardPropsEmits(props, emits) | ||
</script> | ||
|
||
<template> | ||
<TooltipRoot v-bind="forwarded"> | ||
<slot /> | ||
</TooltipRoot> | ||
</template> |
Oops, something went wrong.