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.

Free memory metrics don't include buff/cache

See original GitHub issue

Describe the bug The Java APM agent fails to capture accurate memory and CPU metrics in a containerised env. The cpu and memory statistics for the underlying host are reported NOT the container. This manifests itself in a k8 env but is probably also an issue in a simple docker deployment.

To Reproduce

  1. Deploy an app running in a k8 env - the opbeans example is sufficient. k8 configuration can be provided if needed.
  2. Check metrics tab of agent

image

As illustrated above, memory is always almost 100%. The docs suggest the values of the underlying host are used - in this case 30GB.

{
          "system" : {
            "memory" : {
              "actual" : {
                "free" : 8.82143232E8
              },
              "total" : 3.1629697024E10
            }
          }
        }

dalemcdiarmid@gke-eden-test-default-pool-18a6be9a-8qkm ~ $ free
              total        used        free      shared  buff/cache   available
Mem:       30888376     5974440     1329996        3956    23583940    24656560

Expected behaviour

CPU and memory should represent those of the pod with respect to their limits. Similar to how metricbeat collects.

Debug logs NA

The approach of each agent seems to be different here - the node agent uses cgroups for example.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
felixbarnycommented, May 8, 2019

It has no transitive dependencies.

Correction: it does have a transitive dependency on JNA (not JNI) and JNA can’t be shaded: https://github.com/java-native-access/jna/issues/679. Bummer! It would also add > 3MB to the agent jar file.

I think I’ll start with reading /proc/meminfo for Linux and use OperatingSystemMXBean#getFreePhysicalMemorySize otherwise.

0reactions
axwcommented, May 8, 2019

The Windows implementation of OperatingSystemMXBean.getFreePhysicalMemorySize uses GlobalMemoryStatusEx and returns the ullAvailPhys field of MEMORYSTATUSEX. Similarly, OperatingSystemMXBean.html#getTotalPhysicalMemorySize uses the ullTotalPhys field. Code: https://github.com/openjdk/jdk/blob/master/src/jdk.management/windows/native/libmanagement_ext/OperatingSystemImpl.c#L136-L154.

These are the same values that Metricbeat and the Go agent use. If JNI/JNA is a pain (which it probably is), then you could use OperatingSystemMXBean on Windows.

For macOS, I don’t think it really matters too much if we’re a little inconsistent, which it will be if you use OperatingSystemMXBean there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

linux - confused about buff/cache and available memory metrics
it is showing 759Mi free memory which is relatively large. it is defined to be the unused memory and available memory is defined...
Read more >
Dissecting the free command: What the Linux sysadmin needs ...
The -/+ buffers/cache displays used memory as 42 GB and free memory as 52 GB. This means that the actual quantity of used...
Read more >
"buff/cache" is very high, how I can free it? [duplicate]
1 Answer 1 ... You don't need to free "buff/cache". "buff/cache" is memory that Linux uses for disk caching, and that will be...
Read more >
Free vs. Available Memory in Linux - Hayden James
While available memory is used memory that includes but is not limited to caches and buffers, that can be freed without the performance ......
Read more >
free memory = buff/cache + available memory? — oracle-tech
This should free up any page and slab cache that can be freed up, leaving the absolute bare minimum amount of memory in...
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