Skip to content

Commit 2c71199

Browse files
committed
Add support for 1000 base which is used for network metrics
1 parent 2140499 commit 2c71199

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

redisinsight/ui/src/components/database-overview/components/OverviewMetrics/OverviewMetrics.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ export const getOverviewMetrics = ({ theme, items, db = 0 }: Props): Array<IMetr
119119
},
120120
}
121121

122-
let [networkIn, networkInUnit] = formatBytes(networkInKbps, 3, true)
123-
networkInUnit = `${networkInUnit.toLowerCase()}/s`
124-
let [networkOut, networkOutUnit] = formatBytes(networkOutKbps, 3, true)
125-
networkOutUnit = `${networkOutUnit.toLowerCase()}/s`
122+
let [networkIn, networkInUnit] = formatBytes(networkInKbps * 1000, 3, true, 1000)
123+
console.log(networkInKbps, networkIn, networkInUnit)
124+
networkInUnit = networkInUnit ? `${networkInUnit.toLowerCase()}/s` : ''
125+
let [networkOut, networkOutUnit] = formatBytes(networkOutKbps * 1000, 3, true, 1000)
126+
networkOutUnit = networkOutUnit ? `${networkOutUnit.toLowerCase()}/s` : ''
126127

127128
const networkInItem = {
128129
id: 'network-input',

redisinsight/ui/src/utils/tests/transformers/formatBytes.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ describe('formatBytes', () => {
4747
expect(formatBytes(1572864, 0, true)).toEqual([2, 'MB'])
4848
expect(formatBytes(1347545989, 3, true)).toEqual([1.255, 'GB'])
4949
})
50+
51+
it('should properly set the baseK', () => {
52+
expect(formatBytes(1347545989, 3, true)).toEqual([1.255, 'GB']) // default uses 1024
53+
expect(formatBytes(1347545989, 3, true, 1000)).toEqual([1.348, 'GB'])
54+
})
5055
})
5156

5257
const toBytesTests: any[] = [

redisinsight/ui/src/utils/transformers/formatBytes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ const SIZES = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
33
export const formatBytes = (
44
input: number,
55
decimals: number = 3,
6-
splitResult: boolean = false
6+
splitResult: boolean = false,
7+
baseK = 1024,
78
): string | [number, string] => {
89
try {
910
const bytes = parseFloat(String(input))
10-
const k = 1024
11+
const k = baseK
1112
const dm = decimals < 0 ? 0 : decimals
1213
if (Number.isNaN(bytes) || bytes < 0) return '-'
1314
if (bytes === 0) return `0 ${SIZES[0]}`

0 commit comments

Comments
 (0)