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

System memory metrics #5234

Open
fabcmartins opened this issue Jun 27, 2024 · 4 comments · May be fixed by #5308
Open

System memory metrics #5234

fabcmartins opened this issue Jun 27, 2024 · 4 comments · May be fixed by #5308
Labels
enhancement A general enhancement help wanted An issue that a contributor can help us with instrumentation An issue that is related to instrumenting a component module: micrometer-core An issue that is related to our core module
Milestone

Comments

@fabcmartins
Copy link

fabcmartins commented Jun 27, 2024

The class JvmMemoryMetrics offers memory metrics, but those are all related to heap and non heap values and do not expose the actual memory limits of the machine/container on which the application is running.

It'd be an improvement to offer some additional metrics in this class, such as
system.memory.max
system.memory.used

The metrics are available in the OperatingSystemMXBean classes in the Oracle and IBM JREs, and are already used by Micrometer to expose CPU metrics in the class io.micrometer.core.instrument.binder.system.ProcessorMetrics.

My use case would be to measure my application running inside a container in Kubernetes. With these metrics I would be able to know the percentage of available memory being used by the application.

The io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics is not enough to do it. For instance, by default Metaspace size is unlimited and Micrometer returns -1 when trying to read it.

The most important metric missing is getTotalPhysicalMemorySize, without it there's no way to build a Grafana panel that shows the percentage of memory being used by an application.

@shakuzen shakuzen changed the title Improve exposed memory metrics System memory metrics Jul 2, 2024
@shakuzen shakuzen added enhancement A general enhancement module: micrometer-core An issue that is related to our core module instrumentation An issue that is related to instrumenting a component labels Jul 2, 2024
@shakuzen shakuzen added this to the 1.x milestone Jul 2, 2024
@shakuzen
Copy link
Member

shakuzen commented Jul 2, 2024

Thanks for opening the issue. It's surprising no one else has asked for this yet (as far as I can remember). I suppose it isn't application metrics but rather system metrics and a solution could be to get that from outside of your application somehow. I think it'd be best to add this in a separate binder than JvmMemoryMetrics. Perhaps in a SystemMemoryMetrics class. Though from the JavaDocs of the JMX methods, it sounds like they're trying to move away from the "system" naming. Would you be interested in contributing a pull request for this?

@shakuzen shakuzen added the help wanted An issue that a contributor can help us with label Jul 2, 2024
@mweirauch
Copy link
Contributor

I haven't looked into the details what the JDK specific implementations return, but for the purpose of retrieving system level process metrics I came up with https://github.com/mweirauch/micrometer-jvm-extras which uses procfs (Linux only) to retrieve these metrics. (vss,rss,swap)

I started a draft to also read cgroup memory (limit) metrics, but haven't finished the implementation.

Perhaps that is useful.

@fabcmartins
Copy link
Author

fabcmartins commented Jul 16, 2024

Would you be interested in contributing a pull request for this?

Sure, I'm writing the code. I'm planning on exposing the 5 metrics available in on the following properties:

  • system.virtualmemory.commited
  • system.swap.total
  • system.swap.free
  • system.memory.free
  • system.memory.total

As you already mentioned, Oracle seems to be moving from the term system to environment, maybe I should use a different prefix.

@lenin-jaganathan
Copy link
Contributor

It's surprising no one else has asked for this yet (as far as I can remember). I suppose it isn't application metrics but rather system metrics and a solution could be to get that from outside of your application somehow.

There has been a bit of debate for us about where the responsibility of exposing the system-level metrics lies. Should individual processes report these or should the host (probably some host agent) should be responsible for exposing this information? There are discussions in favor of both sides.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement help wanted An issue that a contributor can help us with instrumentation An issue that is related to instrumenting a component module: micrometer-core An issue that is related to our core module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants