You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "janhoy (via GitHub)" <gi...@apache.org> on 2026/03/12 12:11:27 UTC
[PR] SOLR-18159 Add metrics for system memory [solr]
janhoy opened a new pull request, #4209:
URL: https://github.com/apache/solr/pull/4209
More specifically `jvm_system_memory_free_bytes` and `jjvm_system_memory_total_bytes`
https://issues.apache.org/jira/browse/SOLR-18159
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2927853755
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
Review Comment:
Yea, it's different styles. The otel standard is dot separated, so I think we should stick with dots in the metric registry, and only switch to underscores when we cross a prometheus boundary (such as our metrics endpoint, and on the prometheus-write side of OTEL-collector.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2943495910
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
Review Comment:
Oh, well, I managed to enable OTLP export of metrics, I thought it was not possible. So guess changing from underscore to dot in 10.1 would be a break, unless we classify it as a bug or a BETA feature..
<img width="1028" height="833" alt="Skjermbilde 2026-03-17 kl 00 08 48" src="https://github.com/user-attachments/assets/23c3dbc5-9964-4a52-9e45-8ff6df2fe83b" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "dsmiley (via GitHub)" <gi...@apache.org>.
dsmiley commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2944048546
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
Review Comment:
I'm +1 to break OTLP back-compat in 10.1 if we think this is the right direction.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2927899978
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -74,6 +116,14 @@ public void close() {
if (runtimeMetrics != null && isInitialized) {
try {
runtimeMetrics.close();
+ if (systemMemoryTotalGauge != null) {
+ systemMemoryTotalGauge.close();
+ systemMemoryTotalGauge = null;
+ }
+ if (systemMemoryFreeGauge != null) {
+ systemMemoryFreeGauge.close();
+ systemMemoryFreeGauge = null;
+ }
Review Comment:
These implement `AutoClosable`, not `Closable`, so IOUtils do not like it..
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2927857050
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
Review Comment:
Some JDKs do not support the sun API and will report -1 or maybe 0. So this is a guard against bad value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "mlbiscoc (via GitHub)" <gi...@apache.org>.
mlbiscoc commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2927045246
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -74,6 +116,14 @@ public void close() {
if (runtimeMetrics != null && isInitialized) {
try {
runtimeMetrics.close();
+ if (systemMemoryTotalGauge != null) {
+ systemMemoryTotalGauge.close();
+ systemMemoryTotalGauge = null;
+ }
+ if (systemMemoryFreeGauge != null) {
+ systemMemoryFreeGauge.close();
+ systemMemoryFreeGauge = null;
+ }
Review Comment:
Close with `closeQuietly` then set to null in finally might be cleaner.
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
+ },
+ OtelUnit.BYTES);
+ systemMemoryFreeGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory.free",
+ "Free (unused) physical memory of the host or container in bytes.",
+ measurement -> {
+ long free = extOsMxBean.getFreeMemorySize();
+ if (free > 0) measurement.record(free);
Review Comment:
Same comment as above but having 0 free memory could be possible?
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
+ },
+ OtelUnit.BYTES);
+ systemMemoryFreeGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory.free",
+ "Free (unused) physical memory of the host or container in bytes.",
+ measurement -> {
+ long free = extOsMxBean.getFreeMemorySize();
+ if (free > 0) measurement.record(free);
+ },
+ OtelUnit.BYTES);
Review Comment:
WDYT to make it just `jvm.system.memory` as the name and differ by attribute like "state=total/free` or `type` because the prefixes are the same.
Or `jvm.system.memory` -> `jvm_system_memory_max`? I just want to better have it in the names that this is `total` without having the suffix `total` because then it will be confused with counters as `total` is reserved for that type.
##########
changelog/unreleased/SOLR-18159-physical-memory-metrics.yml:
##########
@@ -0,0 +1,9 @@
+title: Add jvm_system_memory_bytes and jvm_system_memory_free_bytes gauges exposing
+ total and free physical (host or container) memory to the Prometheus metrics endpoint.
Review Comment:
I think its better to just drop `Prometheus metrics endpoint`. Just metrics is fine since we are not only prometheus anymore.
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
Review Comment:
I didn't know the prometheus writer would actually transform these delimited by dots in to underscores. But since we are _ for everything else, then make these underscores.
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
Review Comment:
Curious why the > 0 check? Seems wrong but also could this actually be 0?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2925211419
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,36 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
+ },
Review Comment:
Wrong comment, keeping
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "mlbiscoc (via GitHub)" <gi...@apache.org>.
mlbiscoc commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2942203028
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
Review Comment:
Aw man wish I had done dot separated back then. I should have been more careful. Oh well. Maybe in Solr 11 I will just move the delimiters to dot separated to actually get to that otel standard.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2943201839
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
Review Comment:
As our only external interface in 10.0.0 is the `/solr/admin/metrics` endpoint, it would not be a breaking change to switch to dot separated in 10.1. Who would notice? I hope we can get OTLP export working in 10.1 once that is out of the bag, there would be no way back...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2924267128
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,36 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
+ },
+ OtelUnit.BYTES);
+ systemMemoryFreeGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory.free",
+ "Free (unused) physical memory of the host or container in bytes.",
+ measurement -> {
+ long free = extOsMxBean.getFreeMemorySize();
+ if (free > 0) measurement.record(free);
+ },
+ OtelUnit.BYTES);
+ log.info("Physical memory metrics enabled");
+ } else {
+ log.info(
Review Comment:
The ref-guide says these metrics are “silently absent” when unsupported, but this code logs an INFO message on every startup when `com.sun.management.OperatingSystemMXBean` isn’t present. Consider downgrading these messages to DEBUG (or removing them) or update the documentation to match the actual behavior.
```suggestion
log.debug(
```
##########
solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java:
##########
@@ -105,4 +107,51 @@ public void testSetupJvmMetrics() throws InterruptedException {
"Should have JVM buffer metrics",
metricNames.stream().anyMatch(name -> name.startsWith("jvm_buffer")));
}
+
+ @Test
+ @SuppressForbidden(reason = "Testing com.sun.management.OperatingSystemMXBean availability")
+ public void testSystemMemoryMetrics() {
+ PrometheusMetricReader reader =
+ solrTestRule
+ .getJetty()
+ .getCoreContainer()
+ .getMetricManager()
+ .getPrometheusMetricReader("solr.jvm");
+ MetricSnapshots snapshots = reader.collect();
+
+ Set<String> metricNames =
+ snapshots.stream()
+ .map(metric -> metric.getMetadata().getPrometheusName())
+ .collect(Collectors.toSet());
+
+ // Physical memory metrics are only present on HotSpot JDK (com.sun.management available).
+ // If absent, the test is skipped (graceful degradation is tested separately).
+ boolean isHotSpot =
+ java.lang.management.ManagementFactory.getOperatingSystemMXBean()
+ instanceof com.sun.management.OperatingSystemMXBean;
+ Assume.assumeTrue(
+ "Skipping: com.sun.management.OperatingSystemMXBean not available", isHotSpot);
+
+ assertTrue(
+ "Should have jvm_system_memory_bytes metric",
+ metricNames.contains("jvm_system_memory_bytes"));
+ assertTrue(
+ "Should have jvm_system_memory_free_bytes metric",
+ metricNames.contains("jvm_system_memory_free_bytes"));
+ }
+
+ @Test
+ public void testJvmMetricsDisabledNoSystemMemory() throws Exception {
+ // Verify that when JVM metrics are disabled, initialization is a no-op and close() is safe
+ SolrMetricManager metricManager = solrTestRule.getJetty().getCoreContainer().getMetricManager();
+ System.setProperty("solr.metrics.jvm.enabled", "false");
+ try {
+ OtelRuntimeJvmMetrics disabledMetrics = new OtelRuntimeJvmMetrics();
+ OtelRuntimeJvmMetrics result = disabledMetrics.initialize(metricManager, "solr.jvm");
+ assertFalse("Should not be initialized when JVM metrics disabled", result.isInitialized());
+ disabledMetrics.close(); // must not throw
+ } finally {
+ System.setProperty("solr.metrics.jvm.enabled", "true");
+ }
Review Comment:
This test permanently forces `solr.metrics.jvm.enabled` back to "true" in the `finally` block, which can leak state into other tests (and overrides cases where the property was originally unset). Save the previous value and restore it (or clear the property) after the test.
##########
solr/solr-ref-guide/modules/deployment-guide/pages/metrics-reporting.adoc:
##########
@@ -98,6 +98,21 @@ The `JVM Registry` gathers metrics from the JVM using the OpenTelemetry instrume
JVM metrics are enabled by default but can be disabled by setting either the system property `-Dsolr.metrics.jvm.enabled=false` or the environment variable `SOLR_METRICS_JVM_ENABLED=false`.
+==== Physical Memory Metrics
+
+Solr exposes two additional gauges for host or container physical memory, registered under the `solr.jvm` registry:
+
+[cols="2,1,3",options="header"]
+|===
+| Prometheus Metric Name | Type | Description
+| `jvm_system_memory_bytes` | gauge | Total physical memory of the host or container in bytes. On Linux with cgroup memory limits, reflects the container limit rather than host RAM.
+| `jvm_system_memory_free_bytes` | gauge | Free (unused) physical memory of the host or container in bytes.
+|===
+
+NOTE: These metrics are available only on HotSpot-based JDK distributions (Oracle JDK, Eclipse Temurin, Amazon Corretto, IBM Semeru, and others). On JVMs that do not provide `com.sun.management.OperatingSystemMXBean`, the metrics are silently absent.
Review Comment:
This NOTE claims the metrics are available only on “HotSpot-based JDK distributions” and lists vendors, but the actual availability condition in code is whether `com.sun.management.OperatingSystemMXBean` is present. To avoid misinformation (and vendor lists that can easily be wrong/outdated), consider rephrasing this note to only describe the concrete API requirement (and, if desired, mention “most HotSpot-derived JVMs” without enumerating vendors).
```suggestion
NOTE: These metrics are available when the JVM provides the `com.sun.management.OperatingSystemMXBean` interface (this includes most HotSpot-derived JVMs). On JVMs that do not provide `com.sun.management.OperatingSystemMXBean`, the metrics are silently absent.
```
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,36 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
+ },
+ OtelUnit.BYTES);
+ systemMemoryFreeGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory.free",
+ "Free (unused) physical memory of the host or container in bytes.",
+ measurement -> {
+ long free = extOsMxBean.getFreeMemorySize();
Review Comment:
`com.sun.management.OperatingSystemMXBean` does not define `getFreeMemorySize()` on Java 21, so this won’t compile. Use the appropriate method (e.g., `getFreePhysicalMemorySize()`) and ensure the metric name/description matches the underlying meaning.
```suggestion
"Free (unused) physical memory of the host in bytes.",
measurement -> {
long free = extOsMxBean.getFreePhysicalMemorySize();
```
##########
solr/core/src/test/org/apache/solr/metrics/JvmMetricsTest.java:
##########
@@ -105,4 +107,51 @@ public void testSetupJvmMetrics() throws InterruptedException {
"Should have JVM buffer metrics",
metricNames.stream().anyMatch(name -> name.startsWith("jvm_buffer")));
}
+
+ @Test
+ @SuppressForbidden(reason = "Testing com.sun.management.OperatingSystemMXBean availability")
+ public void testSystemMemoryMetrics() {
+ PrometheusMetricReader reader =
+ solrTestRule
+ .getJetty()
+ .getCoreContainer()
+ .getMetricManager()
+ .getPrometheusMetricReader("solr.jvm");
+ MetricSnapshots snapshots = reader.collect();
+
+ Set<String> metricNames =
+ snapshots.stream()
+ .map(metric -> metric.getMetadata().getPrometheusName())
+ .collect(Collectors.toSet());
+
+ // Physical memory metrics are only present on HotSpot JDK (com.sun.management available).
+ // If absent, the test is skipped (graceful degradation is tested separately).
Review Comment:
The comment says “graceful degradation is tested separately”, but this class doesn’t appear to include a test that asserts behavior when `com.sun.management.OperatingSystemMXBean` is *not* available (this test is just skipped). Either add such a test (e.g., by factoring OS bean access behind a seam that can be substituted) or adjust the comment to avoid implying coverage that isn’t present.
```suggestion
// If absent, the test is skipped.
```
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,36 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
+ },
Review Comment:
`com.sun.management.OperatingSystemMXBean` (at least on the project’s minimum Java 21) does not define `getTotalMemorySize()`, so this won’t compile. Use the correct API method (e.g., `getTotalPhysicalMemorySize()`), and keep the metric description aligned with whatever semantics that method provides (host vs container-aware).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2945149367
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
Review Comment:
I'd rather comply with OTEL standards than with prometheus conventions since I see a clear trend in pushing metrics to other systems than prometheus.
Note: I tried in another system to push dot separated metric names directly into prometheus, and while it worked, it is not pleasant to work with in prometheus/grafana, as you often need to escape things all the time, e.g. write `{"foo.bar.baz"}` rather than just `foo_bar_baz`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2927881538
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
+ },
+ OtelUnit.BYTES);
+ systemMemoryFreeGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory.free",
+ "Free (unused) physical memory of the host or container in bytes.",
+ measurement -> {
+ long free = extOsMxBean.getFreeMemorySize();
+ if (free > 0) measurement.record(free);
Review Comment:
Theoretical, since it is byte. You might have it for a split second but then it will fluctuate. I'm not sure enough about the behavior of all JVMs, if any would return 0 as "don't know" - my LLM obviously thought so and chose to play safe.
Let's consider `>= 0` instead for both, since `-1` seems to be the expected value for no value...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2945149367
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
Review Comment:
I'd rather comply with OTEL standards than with prometheus conventions since I see a clear trend in pushing metrics to other systems than prometheus.
Note: I tried in another system to push dot separated metric names directly into prometheus, and while it worked, it is not pleasant to work with in prometheus/grafana, as you often need to escape things all the time, e.g. write `{"foo.bar.baz"}` rather than just `foo_bar_baz`. So it will be a model where internal representation and OTLP wire-format uses dot syntax, and when you cross the boundary to prometheus, it gets converted to underscore syntax.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "janhoy (via GitHub)" <gi...@apache.org>.
janhoy commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2927984989
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -65,6 +75,38 @@ public ContextPropagators getPropagators() {
// TODO: We should have this configurable to enable/disable specific JVM metrics
.enableAllFeatures()
.build();
+ java.lang.management.OperatingSystemMXBean osMxBean =
+ ManagementFactory.getOperatingSystemMXBean();
+ if (osMxBean instanceof com.sun.management.OperatingSystemMXBean extOsMxBean) {
+ systemMemoryTotalGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory",
+ "Total physical memory of the host or container in bytes."
+ + " On Linux with cgroup limits, reflects the container memory limit.",
+ measurement -> {
+ long total = extOsMxBean.getTotalMemorySize();
+ if (total > 0) measurement.record(total);
+ },
+ OtelUnit.BYTES);
+ systemMemoryFreeGauge =
+ solrMetricManager.observableLongGauge(
+ registryName,
+ "jvm.system.memory.free",
+ "Free (unused) physical memory of the host or container in bytes.",
+ measurement -> {
+ long free = extOsMxBean.getFreeMemorySize();
+ if (free > 0) measurement.record(free);
+ },
+ OtelUnit.BYTES);
Review Comment:
Yea. Currently we do not have a separate panel for system memory, but could add one. Personally I hate it when one panel displays 5 graphs per JVM/node which say very different things, like max, min, free, used. In the new dashboard I therefore try to have one panel for used and another for free.
But even if we merge these into one metric key (I think we should) it is easy to make one or two panels on the visualization layer. What about a panel that shows total-system-mem, heap-max and system-free in the same panel as stacked area graph? Then we'd see the node's total mem and how it is divided between heap, off-heap (where mmap is largest) and free.
As for naming, `jvm.system.memory` is ok, with an attribute `total` one `free`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org
Re: [PR] SOLR-18159 Add metrics for system memory [solr]
Posted by "mlbiscoc (via GitHub)" <gi...@apache.org>.
mlbiscoc commented on code in PR #4209:
URL: https://github.com/apache/solr/pull/4209#discussion_r2942216223
##########
solr/core/src/java/org/apache/solr/metrics/OtelRuntimeJvmMetrics.java:
##########
@@ -17,27 +17,39 @@
package org.apache.solr.metrics;
import io.opentelemetry.api.OpenTelemetry;
+import io.opentelemetry.api.common.AttributeKey;
+import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.MeterProvider;
+import io.opentelemetry.api.metrics.ObservableLongGauge;
import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.instrumentation.runtimemetrics.java17.RuntimeMetrics;
import java.lang.invoke.MethodHandles;
+import java.lang.management.ManagementFactory;
+import org.apache.lucene.util.SuppressForbidden;
import org.apache.solr.common.util.EnvUtils;
+import org.apache.solr.metrics.otel.OtelUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Manages JVM metrics collection using OpenTelemetry Runtime Metrics with JFR features */
public class OtelRuntimeJvmMetrics {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+ private static final AttributeKey<String> STATE_KEY = AttributeKey.stringKey("state");
Review Comment:
I could image something as generic as `state` being used again. How about moving this to `SolrMetricProducer`? Feel free to ignore if you disagree. Don't feel strongly about it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org