From 3078eacecb8a6fa074ea3a363bb963e717fa6b9d Mon Sep 17 00:00:00 2001 From: xusongfu Date: Wed, 12 Oct 2022 16:49:14 +0800 Subject: [PATCH] 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 --- src/resources/prometheus/monitoring.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/resources/prometheus/monitoring.js b/src/resources/prometheus/monitoring.js index 15075664..a0c3fb6f 100644 --- a/src/resources/prometheus/monitoring.js +++ b/src/resources/prometheus/monitoring.js @@ -92,7 +92,7 @@ export const getSuitableValue = ( return defaultValue; } const unit = getSuitableUnit(value, unitType); - const unitText = unit ? ` ${t(unit)}` : ''; + const unitText = unit || ''; const count = getValueByUnit(value, unit || unitType); return `${count}${unitText}`; }; @@ -116,15 +116,19 @@ export const getValueByUnit = (num, unit) => { if (value < 1) return 0; break; case 'KiB': + case 'KiB/s': value /= 1024; break; case 'MiB': + case 'MiB/s': value /= 1024 ** 2; break; case 'GiB': + case 'GiB/s': value /= 1024 ** 3; break; case 'TiB': + case 'TiB/s': value /= 1024 ** 4; break; case 'Bytes':