fix: Fix the unit transform in prometheus monitor

1. Fix getValueByUnit to get correct value
2. Fix the unit text, it doesn't need i18n

Closes-Bug: #1992407
Change-Id: I6add661f739447666f80308e36991e07f0e8b4aa
This commit is contained in:
xusongfu 2022-10-12 16:49:14 +08:00
parent 1506dd9353
commit 3078eacecb

View File

@ -92,7 +92,7 @@ export const getSuitableValue = (
return defaultValue; return defaultValue;
} }
const unit = getSuitableUnit(value, unitType); const unit = getSuitableUnit(value, unitType);
const unitText = unit ? ` ${t(unit)}` : ''; const unitText = unit || '';
const count = getValueByUnit(value, unit || unitType); const count = getValueByUnit(value, unit || unitType);
return `${count}${unitText}`; return `${count}${unitText}`;
}; };
@ -116,15 +116,19 @@ export const getValueByUnit = (num, unit) => {
if (value < 1) return 0; if (value < 1) return 0;
break; break;
case 'KiB': case 'KiB':
case 'KiB/s':
value /= 1024; value /= 1024;
break; break;
case 'MiB': case 'MiB':
case 'MiB/s':
value /= 1024 ** 2; value /= 1024 ** 2;
break; break;
case 'GiB': case 'GiB':
case 'GiB/s':
value /= 1024 ** 3; value /= 1024 ** 3;
break; break;
case 'TiB': case 'TiB':
case 'TiB/s':
value /= 1024 ** 4; value /= 1024 ** 4;
break; break;
case 'Bytes': case 'Bytes':