question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DiskSpaceMetrics returns NaN when garbage collected

See original GitHub issue

When using standard DiskSpaceMetrics, metrics returned are always NaN Jon said that it is a known issue:

there is an issue with that binder where we should have used a strong reference gauge

Jon also has given a workaround:

Iterable<Tag> tagsWithPath = Tags.concat(tags, "path", absolutePath);
        Gauge.builder("disk.free", path, File::getUsableSpace)
                .strongReference(true)
                .tags(tagsWithPath)
                .description("Usable space for path")
                .baseUnit("bytes")
                .register(registry);
        Gauge.builder("disk.total", path, File::getTotalSpace)
                .strongReference(true)
                .tags(tagsWithPath)
                .description("Total space for path")
                .baseUnit("bytes")
                .register(registry);

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
shakuzencommented, Jun 12, 2019

I think that that would work if a reference to DiskSpaceMetrics was retained in using code. However, I assume some (or most?) users do the following: new DiskSpaceMetrics(new File("/"), tags).bindTo(compositeRegistry); in which case the path as well as the DiskSpaceMetrics object won’t be retained.

@roded thank you for having the patience to explain how this could be reproduced. I have now reproduced this and we’ll get it fixed.

0reactions
rodedcommented, Jun 12, 2019

I’m experiencing the same issue with micrometer 1.1.4. Setting the Gauge’s strongReference to true has resolved the issue as suggested.

@shakuzen, regarding the path reference: I think that that would work if a reference to DiskSpaceMetrics was retained in using code. However, I assume some (or most?) users do the following: new DiskSpaceMetrics(new File("/"), tags).bindTo(compositeRegistry); in which case the path as well as the DiskSpaceMetrics object won’t be retained.

I believe that this issue should be reopened.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do reading Micrometer measurement returns NaN ...
Since the gauge doesn't hold a strong reference to the object, when the object is garbage collected, the value becomes NaN .
Read more >
gc — Garbage Collector interface — Python 3.11.1 ...
Returns a list of all objects tracked by the collector, excluding the list returned. If generation is not None, return only the objects...
Read more >
gc: Garbage Collection - Rdrr.io
gc returns a matrix with rows "Ncells" (cons cells), usually 28 bytes each on 32-bit systems and 56 bytes on 64-bit systems, and...
Read more >
Is there Garbage Collection in C and C++? - YouTube
Patreon ➤ https://www.patreon.com/jacobsorberCourses ➤ https://jacobsorber.thinkific.comWebsite ➤ https://www.jacobsorber.com---Is there ...
Read more >
Writing a Mark-Sweep Garbage Collector - Dmitry Soshnikov
By itself the “garbage collection” topic relates to abstract ... the most popular of which are the Tagged pointers and NaN-boxing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found