diff --git a/solr/core/src/java/org/apache/solr/servlet/PrometheusMetricsServlet.java b/solr/core/src/java/org/apache/solr/servlet/PrometheusMetricsServlet.java index 1240822e568..dac9c33110f 100644 --- a/solr/core/src/java/org/apache/solr/servlet/PrometheusMetricsServlet.java +++ b/solr/core/src/java/org/apache/solr/servlet/PrometheusMetricsServlet.java @@ -31,6 +31,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; @@ -72,9 +73,10 @@ public final class PrometheusMetricsServlet extends BaseSolrServlet { new OsMetricsApiCaller(), new ThreadMetricsApiCaller(), new StatusCodeMetricsApiCaller(), - new CoresMetricsApiCaller())); + new CoresMetricsApiCaller(), + new NodeCacheMetricsApiCaller())); - private final Map cacheMetricTypes = + private static final Map cacheMetricTypes = Map.of( "bytesUsed", PrometheusMetricType.GAUGE, "lookups", PrometheusMetricType.COUNTER, @@ -143,6 +145,41 @@ static void getSharedCacheMetrics( } } + static class NodeCacheMetricsApiCaller extends MetricsApiCaller { + private static final String PREFIX = "CACHE.nodeLevelCache/"; + NodeCacheMetricsApiCaller() { + super( + "node", + PREFIX, + ""); + } + + @Override + protected void handle(List results, JsonNode metrics) throws IOException { + JsonNode parent = metrics.path("solr.node"); + Iterator> caches = parent.fields(); + while (caches.hasNext()) { + Map.Entry cacheEntry = caches.next(); + String cacheName = cacheEntry.getKey().substring(PREFIX.length()).toLowerCase(Locale.ROOT); + Iterator> fields = cacheEntry.getValue().fields(); + while (fields.hasNext()) { + Map.Entry next = fields.next(); + String fieldName = next.getKey(); + PrometheusMetricType type = cacheMetricTypes.get(fieldName); + if (type != null) { + results.add( + new PrometheusMetric( + String.format(Locale.ROOT, "cache_%s_%s", cacheName, fieldName), + type, + String.format( + Locale.ROOT, "%s %s for cache %s", fieldName, type.getDisplayName(), cacheName), + next.getValue().numberValue())); + } + } + } + } + } + static class GarbageCollectorMetricsApiCaller extends MetricsApiCaller { GarbageCollectorMetricsApiCaller() {