ks888 / LambStatus

[Maintenance mode] Serverless Status Page System
https://lambstatus.github.io
Apache License 2.0
1.3k stars 120 forks source link

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

Open skyzyx opened 7 years ago

skyzyx commented 7 years ago

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

ks888 commented 7 years ago

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:

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 commented 7 years ago

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.

ryangravetteadmin commented 7 years ago

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

jpike88 commented 6 years ago

A javascript solution is best and simplest I think