Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Capacity formating error #367

Closed
Virsacer opened this issue May 4, 2022 · 5 comments
Closed

Memory Capacity formating error #367

Virsacer opened this issue May 4, 2022 · 5 comments
Milestone

Comments

@Virsacer
Copy link
Contributor

Virsacer commented May 4, 2022

Expected Behavior

Capacity: 1.00 TiB

Current Behavior

Capacity: 1.02E+3 GiB

Possible Solution

Probably some rounding error since machines with 2 TiB produce Capacity: 1.99 TiB

Steps to Reproduce (for bugs)

Well, have a machine with 1TiB
Or 1023 GiB perhaps!?
And go to the host-page.

Your Environment

  • VMware vCenter®/ESXi™-Version: 7.0.3
  • Version/GIT-Hash of this module: 1.4.0
  • Icinga Web 2 version: 2.10.1
  • Operating System and version: Oracle Linux 7
  • Webserver, PHP versions: 7.3.29
@Thomas-Gelf
Copy link
Contributor

Interesting... can be reproduced, I got one:

Bildschirmfoto von 2022-05-05 08-59-25

@Thomas-Gelf Thomas-Gelf added this to the v1.4.1 milestone May 5, 2022
@Thomas-Gelf
Copy link
Contributor

Problematic values are between 1000 and 1024, in my example it was 1023.185546875. Formatter uses %.3G, expects three digits and therefore fails for values > 999. 1024 should be fine, I guess your capacity is slightly lower than 1 TiB (IEC/binary prefix). You can verify this by temporarily modifying library/Vspheredb/Format.php as follows:

+        return sprintf('%s%.3G %s', $sign, $result, $units[$pow]);
-        return sprintf('%s%s %s', $sign, $result, $units[$pow]);

@Virsacer
Copy link
Contributor Author

Virsacer commented May 5, 2022

Yes, they are betweeen 1019 and 1023
My dirty fix one line above:

    if ($result > 999) $result = $value / pow($base, ++$pow);

@Thomas-Gelf
Copy link
Contributor

This should also do the trick:

-        $pow = floor(log($value, $base));
+        $pow = floor(log($value, 1000));

However, you then get 0.987 (or 0,987, depending on your localization) - and I want to see 0.99 in this case (not more then three characters, ignoring the dot/comma)

@Thomas-Gelf
Copy link
Contributor

Should be fixed now. Related commit 880e091 deals with values between 0 and 1, which (as we're talking about Bytes) in theory should not occur. But who knows, there might be rounding errors when calculating free space. So I addressed that one too, just to be on the safe side.

Thanks for reporting this!

@Thomas-Gelf Thomas-Gelf modified the milestones: v1.4.1, v1.5.0 Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants