prometheus / procfs

procfs provides functions to retrieve system, kernel and process metrics from the pseudo-filesystem proc.
Apache License 2.0
754 stars 311 forks source link

fix(meminfo): account for optional unit field so values are accurate #569

Closed tjhop closed 9 months ago

tjhop commented 9 months ago

Addresses: #565

Previously, this function was ignoring the optional unit field, leading to incorrect results on systems that do report the field. This uses the humanize lib used elsewhere within the Prometheus ecosystem to normalize the value to bytes, including when a unit is provided.

tjhop commented 9 months ago

I had similar thoughts and was considering suggesting a complimentary struct/function for MeminfoBytes, parseMeminfoBytes(), fs.MeminfoBytes(), etc so that the existing code would continue to work as expected.

I think adding in new struct fields for the scaled values to live alongside the raw/unscaled values is a clever solution. I'll work on it 👍

tjhop commented 9 months ago

@SuperQ I revamped a bit to try the shadow struct fields, lemme know your thoughts

tjhop commented 9 months ago

Amended the last commit to fix an accidental deleted line (thank you tests). Force pushed to fix. Only the last commit was amended, so I believe the approval should still be valid since that commit wasn't touched.

discordianfish commented 9 months ago

Great, thanks!