Free memory metrics don't include buff/cache
See original GitHub issueDescribe 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
- Deploy an app running in a k8 env - the opbeans example is sufficient. k8 configuration can be provided if needed.
- Check metrics tab of agent
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:
- Created 4 years ago
- Comments:10 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 useOperatingSystemMXBean#getFreePhysicalMemorySize
otherwise.The Windows implementation of
OperatingSystemMXBean.getFreePhysicalMemorySize
usesGlobalMemoryStatusEx
and returns theullAvailPhys
field of MEMORYSTATUSEX. Similarly,OperatingSystemMXBean.html#getTotalPhysicalMemorySize
uses theullTotalPhys
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.