LambStatus icon indicating copy to clipboard operation
LambStatus copied to clipboard

Format CloudWatch bytes into kb, MB, GB, TB, etc.

Open skyzyx opened this issue 7 years ago • 4 comments

CloudWatch data comes back as bytes. Being able to convert 4352360851042 into 3.958 TB would be useful and more human-friendly.

skyzyx avatar Aug 01 '17 03:08 skyzyx

Thank you for your suggestion. Yes, the current appearance is not user-friendly when the value is large. To read the value like 1000000000 is pretty suffering.

I come up with 3 options to solve this issue:

  • Option 1. add commas to group every three digits. 1000000000 will be 1,000,000,000.
  • Option 2. repeatedly divide the value by 1000. 1000000000 will be 1G.
  • Option 3. repeatedly divide the value by 1024. 1000000000 will be 953.6M.

In the case of bytes, the option 3 is preferable. But the option 2 looks suitable to show the response time or the number of API calls.

Also, I guess a visitor to the status page can't immediately realize whether 1G means 1000000000 or 1073741824.

So I think the option 1 is the more general and less confusing than others, though it's a little harder to read if the value is very large.

ks888 avatar Aug 11 '17 07:08 ks888

As the quick fix, I've implemented the option 1 and it will be available since v0.4.0. But I'm going to keep this issue open for a while since I'd like to know more opinions.

ks888 avatar Aug 13 '17 11:08 ks888

How about setting a data type and then using javascript on the front end to make it user readable based on the type?

function bytesToSize(bytes) { var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; if (bytes == 0) return '0 Byte'; var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; };

Source: https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript

ryangravetteadmin avatar Aug 15 '17 23:08 ryangravetteadmin

A javascript solution is best and simplest I think

jpike88 avatar Nov 25 '17 06:11 jpike88