@@ -57,7 +57,7 @@ import {
57
57
TableDataFormatterProps ,
58
58
TextWithLinkFormatterProps
59
59
} from './types' ;
60
- import { splitCamelCaseString } from './utils' ;
60
+ import { parseCpu , splitCamelCaseString } from './utils' ;
61
61
62
62
interface ResourceProgressProps {
63
63
title : string ;
@@ -368,10 +368,12 @@ export const MemoryUsage: React.FC<MemoryUsageProps> = ({
368
368
return parseInt ( kiValue . replace ( 'Ki' , '' ) ) * 1024 ;
369
369
} , [ ] ) ;
370
370
371
- const cpuUsage = useMemo ( ( ) => {
371
+ const reservedCpu = useMemo ( ( ) => {
372
372
if ( ! allocatable || ! capacity ) return 0 ;
373
- const usedCPU = parseInt ( capacity . cpu ) - parseInt ( allocatable . cpu ) ;
374
- return ( usedCPU / parseInt ( capacity . cpu ) ) * 100 ;
373
+ const usedCPU = parseCpu ( capacity . cpu ) - parseCpu ( allocatable . cpu ) ;
374
+ const capacityCPU = parseCpu ( capacity . cpu ) ;
375
+
376
+ return ( usedCPU / capacityCPU ) * 100 ;
375
377
} , [ allocatable , capacity ] ) ;
376
378
377
379
const memoryUsage = useMemo ( ( ) => {
@@ -382,12 +384,14 @@ export const MemoryUsage: React.FC<MemoryUsageProps> = ({
382
384
return ( usedMemory / totalMemory ) * 100 ;
383
385
} , [ allocatable , capacity ] ) ;
384
386
385
- const diskUsage = useMemo ( ( ) => {
387
+ const diskUsagePercent = useMemo ( ( ) => {
386
388
if ( ! allocatable || ! capacity ) return 0 ;
387
- const totalStorageInBytes = convertKiToBytes ( capacity [ 'ephemeral-storage' ] ) ;
388
- const availableStorageInBytes = parseInt ( allocatable [ 'ephemeral-storage' ] ) ;
389
- const usedStorageInBytes = totalStorageInBytes - availableStorageInBytes ;
390
- return ( usedStorageInBytes / totalStorageInBytes ) * 100 ;
389
+
390
+ const total = convertKiToBytes ( capacity [ 'ephemeral-storage' ] ) ;
391
+ const available = convertKiToBytes ( allocatable [ 'ephemeral-storage' ] ) ;
392
+
393
+ const used = total - available ;
394
+ return ( used / total ) * 100 ;
391
395
} , [ allocatable , capacity , convertKiToBytes ] ) ;
392
396
393
397
const chartOptions = useCallback (
@@ -439,9 +443,9 @@ export const MemoryUsage: React.FC<MemoryUsageProps> = ({
439
443
440
444
return (
441
445
< FlexResourceContainer >
442
- < ResourceProgress title = "CPU Usage " percentage = { cpuUsage } type = { 'CPU' } />
446
+ < ResourceProgress title = "System Reserved Cpu " percentage = { reservedCpu } type = { 'CPU' } />
443
447
< ResourceProgress title = "Memory Usage" percentage = { memoryUsage } type = { 'Memory' } />
444
- < ResourceProgress title = "Disk Usage" percentage = { diskUsage } type = { 'Disk' } />
448
+ < ResourceProgress title = "Disk Usage" percentage = { diskUsagePercent } type = { 'Disk' } />
445
449
</ FlexResourceContainer >
446
450
) ;
447
451
} ;
0 commit comments