All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tangosol.coherence.management.internal.MetricsResource Maven / Gradle / Ivy

/*
 * Copyright (c) 2024, Oracle and/or its affiliates.
 *
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * https://oss.oracle.com/licenses/upl.
 */
package com.tangosol.coherence.management.internal;

import com.tangosol.internal.metrics.MetricsFormatter;
import com.tangosol.internal.metrics.MetricsHttpHandler;

import jakarta.annotation.security.PermitAll;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;

/**
 * A JAX-RS resource that supports metrics requests for managed Coherence server.
 *
 * @author jk, lsho 2024.07.18
 * @since 14.1.2.0.0
 */
@PermitAll
@Path("coherence/metrics")
public class MetricsResource
        extends MetricsHttpHandler
    {
    // ----- constructors ---------------------------------------------------

    /**
     * Create a MetricsResource.
     * 

* This constructor will be used by JAX-RS to create the resource instance. *

* The {@code coherence.metrics.legacy.names} system property will be used to * determine whether legacy metric names ot Microprofile compatible metric * names will be used when publishing Prometheus formatted metrics. */ public MetricsResource() { super(); } /** * Create a MetricsResource. * * @param format the format to use for metric names and tag keys. */ MetricsResource(Format format) { super(format); } // ----- MetricsResource methods ---------------------------------------- /** * Obtain the current Prometheus metrics data for all metrics. * * @return the current Prometheus metrics data for all metrics */ @GET @Produces(MediaType.TEXT_PLAIN) public MetricsFormatter getPrometheusMetrics(@Context UriInfo uriInfo) { final MetricPredicate predicate = new MetricPredicate(null, uriInfo.getQueryParameters()); return getPrometheusMetrics(predicate, useExtendedFormat(uriInfo)); } /** * Obtain the current Prometheus metrics data for a metric name. *

* All metrics matching the specified name will be returned. * Metrics can be further filtered by specifying query parameters. * Each name/value pair in the query parameters is used to match * the metric tag values of the metrics returned. Not all of a * metrics tags need to be specified, matching is only done on * the tags specified in the query parameters, the metric will * match even if it has extra tags not specified in the query * parameters. * * @return the current metrics data for a metric name */ @GET @Path("{metric}") @Produces(MediaType.TEXT_PLAIN) public MetricsFormatter getPrometheusMetrics(@PathParam("metric") String sName, @Context UriInfo uriInfo) { final MetricPredicate predicate = new MetricPredicate(sName, uriInfo.getQueryParameters()); return getPrometheusMetrics(predicate, useExtendedFormat(uriInfo)); } /** * Obtain the current JSON formatted metrics data for all metrics. * * @return the current JSON formatted metrics data for all metrics */ @GET @Produces(MediaType.APPLICATION_JSON) public MetricsFormatter getJsonMetrics(@Context UriInfo uriInfo) { final MetricPredicate predicate = new MetricPredicate(null, uriInfo.getQueryParameters()); return getJsonMetrics(predicate, useExtendedFormat(uriInfo)); } /** * Obtain the current JSON formatted metrics data for a metric name. *

* All metrics matching the specified name will be returned. Metrics * can be further filtered by specifying query parameters. * Each name/value pair in the query parameters is used to match the * metric tag values of the metrics returned. Not all of a metrics * tags need to be specified, matching is only done on the tags specified * in the query parameters, the metric will match even if it has extra * tags not specified in the query parameters. * * @return the current metrics data for a metric name */ @GET @Path("{metric}") @Produces(MediaType.APPLICATION_JSON) public MetricsFormatter getJsonMetrics(@PathParam("metric") String sName, @Context UriInfo uriInfo) { final MetricPredicate predicate = new MetricPredicate(sName, uriInfo.getQueryParameters()); return getJsonMetrics(predicate, useExtendedFormat(uriInfo)); } // ----- helper methods ------------------------------------------------- private boolean useExtendedFormat(UriInfo uriInfo) { return f_fAlwaysUseExtended || "true".equalsIgnoreCase(uriInfo.getQueryParameters().getFirst("extended")); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy