diff --git a/jvb/src/main/java/org/jitsi/videobridge/rest/prometheus/Prometheus.java b/jvb/src/main/java/org/jitsi/videobridge/rest/prometheus/Prometheus.java index 0e67d409f9..454b06f774 100644 --- a/jvb/src/main/java/org/jitsi/videobridge/rest/prometheus/Prometheus.java +++ b/jvb/src/main/java/org/jitsi/videobridge/rest/prometheus/Prometheus.java @@ -16,12 +16,15 @@ package org.jitsi.videobridge.rest.prometheus; -import io.prometheus.client.exporter.common.*; import jakarta.ws.rs.*; import jakarta.ws.rs.core.*; +import kotlin.*; import org.jetbrains.annotations.NotNull; import org.jitsi.metrics.*; +import java.util.*; +import java.util.stream.*; + /** * A REST endpoint exposing JVB stats for Prometheus. * Any scraper supporting Prometheus' text-based formats ({@code text/plain; version=0.0.4} or OpenMetrics) @@ -35,6 +38,13 @@ @Path("/metrics") public class Prometheus { + static private final Comparator comparator = Comparator.comparing(Prometheus::getQValue).reversed(); + + private static double getQValue(MediaType m) + { + return m.getParameters().get("q") == null ? 1.0 : Double.parseDouble(m.getParameters().get("q")); + } + @NotNull private final MetricsContainer metricsContainer; @@ -44,23 +54,16 @@ public Prometheus(@NotNull MetricsContainer metricsContainer) } @GET - @Produces(TextFormat.CONTENT_TYPE_004) - public String getPrometheusPlainText() - { - return metricsContainer.getPrometheusMetrics(TextFormat.CONTENT_TYPE_004); - } - - @GET - @Produces(TextFormat.CONTENT_TYPE_OPENMETRICS_100) - public String getPrometheusOpenMetrics() + public Response x(@HeaderParam("Accept") String accept) { - return metricsContainer.getPrometheusMetrics(TextFormat.CONTENT_TYPE_OPENMETRICS_100); - } + List acceptMediaTypes + = Arrays.stream(accept.split(",")) + .map(MediaType::valueOf) + .sorted(comparator) + .map(m -> m.getType() + "/" + m.getSubtype()) + .collect(Collectors.toList()); + Pair m = metricsContainer.getMetrics(acceptMediaTypes); - @GET - @Produces(MediaType.APPLICATION_JSON) - public String getJsonString() - { - return metricsContainer.getJsonString(); + return Response.ok(m.getFirst(), m.getSecond()).build(); } }