Search in sources :

Example 1 with NoSuchMetricException

use of fish.payara.microprofile.metrics.exception.NoSuchMetricException in project Payara by payara.

the class MetricsService method getMetricsAsMap.

public Map<String, Metric> getMetricsAsMap(String registryName, String metricName) throws NoSuchRegistryException, NoSuchMetricException {
    MetricRegistry registry = getRegistry(registryName);
    Map<String, Metric> metricMap = registry.getMetrics();
    if (metricMap.containsKey(metricName)) {
        return singletonMap(metricName, metricMap.get(metricName));
    } else {
        throw new NoSuchMetricException(metricName);
    }
}
Also used : NoSuchMetricException(fish.payara.microprofile.metrics.exception.NoSuchMetricException) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Metric(org.eclipse.microprofile.metrics.Metric)

Example 2 with NoSuchMetricException

use of fish.payara.microprofile.metrics.exception.NoSuchMetricException in project Payara by payara.

the class MetricsResource method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>OPTIONS</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    MetricsService metricsService = Globals.getDefaultBaseServiceLocator().getService(MetricsService.class);
    if (!metricsService.isMetricsEnabled()) {
        response.sendError(SC_FORBIDDEN, "MP Metrics is disabled");
        return;
    }
    if (!request.isSecure() && metricsService.isMetricsSecure()) {
        response.sendError(SC_FORBIDDEN, "MP Metrics security is enabled");
        return;
    }
    MetricsRequest metricsRequest = new MetricsRequest(request);
    try {
        if (metricsRequest.isRegistryRequested() && !REGISTRY_NAMES.contains(metricsRequest.getRegistryName())) {
            throw new NoSuchRegistryException(metricsRequest.getRegistryName());
        }
        MetricsWriter outputWriter = getOutputWriter(request, response);
        if (outputWriter != null) {
            setContentType(outputWriter, response);
            if (metricsRequest.isRegistryRequested() && metricsRequest.isMetricRequested()) {
                outputWriter.write(metricsRequest.getRegistryName(), metricsRequest.getMetricName());
            } else if (metricsRequest.isRegistryRequested()) {
                outputWriter.write(metricsRequest.getRegistryName());
            } else {
                outputWriter.write();
            }
        }
    } catch (NoSuchRegistryException ex) {
        response.sendError(SC_NOT_FOUND, String.format("[%s] registry not found", metricsRequest.getRegistryName()));
    } catch (NoSuchMetricException ex) {
        response.sendError(SC_NOT_FOUND, String.format("[%s] metric not found", metricsRequest.getMetricName()));
    }
}
Also used : MetricsWriter(fish.payara.microprofile.metrics.writer.MetricsWriter) NoSuchRegistryException(fish.payara.microprofile.metrics.exception.NoSuchRegistryException) NoSuchMetricException(fish.payara.microprofile.metrics.exception.NoSuchMetricException) MetricsService(fish.payara.microprofile.metrics.MetricsService)

Example 3 with NoSuchMetricException

use of fish.payara.microprofile.metrics.exception.NoSuchMetricException in project Payara by payara.

the class JsonWriter method write.

@Override
public void write(String registryName, String metricName) throws NoSuchRegistryException, NoSuchMetricException, IOException {
    if (APPLICATION.getName().equals(registryName)) {
        JsonObjectBuilder payloadBuilder = Json.createObjectBuilder();
        for (String appRegistryName : service.getApplicationRegistryNames()) {
            try {
                payloadBuilder.addAll(getJsonData(appRegistryName, metricName));
            } catch (NoSuchMetricException e) {
            // ignore
            }
        }
        JsonObject payload = payloadBuilder.build();
        if (payload.isEmpty()) {
            throw new NoSuchMetricException(metricName);
        } else {
            serialize(payload);
        }
    } else {
        serialize(getJsonData(registryName, metricName).build());
    }
}
Also used : NoSuchMetricException(fish.payara.microprofile.metrics.exception.NoSuchMetricException) JsonObject(javax.json.JsonObject) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 4 with NoSuchMetricException

use of fish.payara.microprofile.metrics.exception.NoSuchMetricException in project Payara by payara.

the class MetricsService method getMetadataAsMap.

public Map<String, Metadata> getMetadataAsMap(String registryName, String metricName) throws NoSuchRegistryException, NoSuchMetricException {
    MetricRegistry registry = getRegistry(registryName);
    Map<String, Metadata> metricMetadataMap = registry.getMetadata();
    if (metricMetadataMap.containsKey(metricName)) {
        return singletonMap(metricName, metricMetadataMap.get(metricName));
    } else {
        throw new NoSuchMetricException(metricName);
    }
}
Also used : NoSuchMetricException(fish.payara.microprofile.metrics.exception.NoSuchMetricException) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) MBeanMetadataHelper.registerMetadata(fish.payara.microprofile.metrics.jmx.MBeanMetadataHelper.registerMetadata) Metadata(org.eclipse.microprofile.metrics.Metadata)

Aggregations

NoSuchMetricException (fish.payara.microprofile.metrics.exception.NoSuchMetricException)4 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)2 MetricsService (fish.payara.microprofile.metrics.MetricsService)1 NoSuchRegistryException (fish.payara.microprofile.metrics.exception.NoSuchRegistryException)1 MBeanMetadataHelper.registerMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadataHelper.registerMetadata)1 MetricsWriter (fish.payara.microprofile.metrics.writer.MetricsWriter)1 JsonObject (javax.json.JsonObject)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 Metadata (org.eclipse.microprofile.metrics.Metadata)1 Metric (org.eclipse.microprofile.metrics.Metric)1