LambStatus
LambStatus copied to clipboard
Format CloudWatch bytes into kb, MB, GB, TB, etc.
CloudWatch data comes back as bytes. Being able to convert 4352360851042
into 3.958 TB
would be useful and more human-friendly.
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 be1,000,000,000
. - Option 2. repeatedly divide the value by 1000.
1000000000
will be1G
. - Option 3. repeatedly divide the value by 1024.
1000000000
will be953.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.
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.
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
A javascript solution is best and simplest I think