org.jitsi.rest.prometheus.Prometheus Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jicoco-metrics Show documentation
Show all versions of jicoco-metrics Show documentation
Jitsi Common Components (Metrics)
The newest version!
/*
* Copyright @ 2022 - present 8x8, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.rest.prometheus;
import io.prometheus.client.exporter.common.*;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.*;
import org.jetbrains.annotations.NotNull;
import org.jitsi.metrics.*;
/**
* A REST endpoint exposing JVB stats for Prometheus.
* Any scraper supporting Prometheus' text-based formats ({@code text/plain; version=0.0.4} or OpenMetrics)
* is compatible with this {@code /metrics} endpoint.
* JSON is provided when the client performs a request with the 'Accept' header set to {@code application/json}.
* The response defaults to {@code text/plain; version=0.0.4} formatted output.
*
* @see
* Prometheus' exposition formats
*/
@Path("/metrics")
public class Prometheus
{
@NotNull
private final MetricsContainer metricsContainer;
public Prometheus(@NotNull MetricsContainer metricsContainer)
{
this.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()
{
return metricsContainer.getPrometheusMetrics(TextFormat.CONTENT_TYPE_OPENMETRICS_100);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getJsonString()
{
return metricsContainer.getJsonString();
}
}