Search in sources :

Example 1 with Type

use of org.eclipse.microprofile.metrics.MetricRegistry.Type in project Payara by payara.

the class MetricsServiceImpl method processMetadataToAnnotations.

private static void processMetadataToAnnotations(MetricsContextImpl context, MonitoringDataCollector collector) {
    RegisteredMetric metric = context.pollNewlyRegistered();
    while (metric != null) {
        MetricID metricID = metric.id;
        Type scope = metric.scope;
        MetricRegistry registry = context.getRegistry(scope);
        MonitoringDataCollector metricCollector = tagCollector(context.getName(), metricID, collector);
        Metadata metadata = registry.getMetadata(metricID.getName());
        String suffix = "Count";
        String property = "Count";
        boolean isGauge = metadata.getTypeRaw() == MetricType.GAUGE;
        if (isGauge) {
            suffix = getMetricUnitSuffix(metadata.unit());
            property = "Value";
        }
        // Note that by convention an annotation with value 0 done before the series collected any value is considered permanent
        metricCollector.annotate(toName(metricID, suffix), 0, false, metadataToAnnotations(context.getName(), scope, metadata, property));
        metric = context.pollNewlyRegistered();
    }
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) MetricID(org.eclipse.microprofile.metrics.MetricID) MetricType(org.eclipse.microprofile.metrics.MetricType) Type(org.eclipse.microprofile.metrics.MetricRegistry.Type) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Metadata(org.eclipse.microprofile.metrics.Metadata) MBeanMetadata(fish.payara.microprofile.metrics.jmx.MBeanMetadata)

Example 2 with Type

use of org.eclipse.microprofile.metrics.MetricRegistry.Type 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.isEnabled()) {
        response.sendError(SC_FORBIDDEN, "MicroProfile Metrics Service is disabled");
        return;
    }
    metricsService.refresh();
    String pathInfo = request.getPathInfo() != null ? request.getPathInfo().substring(1) : EMPTY_STRING;
    String[] pathInfos = pathInfo.split("/");
    String registryName = pathInfos.length > 0 ? pathInfos[0] : null;
    String metricName = pathInfos.length > 1 ? pathInfos[1] : null;
    try {
        String contentType = getContentType(request, response);
        if (contentType != null) {
            response.setContentType(contentType);
            response.setCharacterEncoding(UTF_8.name());
            MetricsWriter outputWriter = getOutputWriter(request, response, metricsService, contentType);
            if (outputWriter != null) {
                if (registryName != null && !registryName.isEmpty()) {
                    Type scope;
                    try {
                        scope = Type.valueOf(registryName.toUpperCase());
                    } catch (RuntimeException ex) {
                        throw new NoSuchRegistryException(registryName);
                    }
                    if (metricName != null && !metricName.isEmpty()) {
                        outputWriter.write(scope, metricName);
                    } else {
                        outputWriter.write(scope);
                    }
                } else {
                    outputWriter.write();
                }
            }
        }
    } catch (NoSuchRegistryException ex) {
        response.sendError(SC_NOT_FOUND, String.format("[%s] registry not found", registryName));
    } catch (NoSuchMetricException ex) {
        response.sendError(SC_NOT_FOUND, String.format("[%s] metric not found", metricName));
    }
}
Also used : MetricsWriter(fish.payara.microprofile.metrics.writer.MetricsWriter) MediaType(javax.ws.rs.core.MediaType) Type(org.eclipse.microprofile.metrics.MetricRegistry.Type) NoSuchRegistryException(fish.payara.microprofile.metrics.exception.NoSuchRegistryException) NoSuchMetricException(fish.payara.microprofile.metrics.exception.NoSuchMetricException) MetricsService(fish.payara.microprofile.metrics.MetricsService)

Aggregations

Type (org.eclipse.microprofile.metrics.MetricRegistry.Type)2 MetricsService (fish.payara.microprofile.metrics.MetricsService)1 NoSuchMetricException (fish.payara.microprofile.metrics.exception.NoSuchMetricException)1 NoSuchRegistryException (fish.payara.microprofile.metrics.exception.NoSuchRegistryException)1 MBeanMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadata)1 MetricsWriter (fish.payara.microprofile.metrics.writer.MetricsWriter)1 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)1 MediaType (javax.ws.rs.core.MediaType)1 Metadata (org.eclipse.microprofile.metrics.Metadata)1 MetricID (org.eclipse.microprofile.metrics.MetricID)1 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)1 MetricType (org.eclipse.microprofile.metrics.MetricType)1