Search in sources :

Example 1 with MetricsWriterImpl

use of fish.payara.microprofile.metrics.writer.MetricsWriterImpl in project Payara by payara.

the class MicroProfileMetricsCheck method constructOptions.

@Override
public synchronized HealthCheckMicroProfileMetricstExecutionOptions constructOptions(MicroProfileMetricsChecker checker) {
    Set<String> metricNames = new HashSet<>();
    for (MonitoredMetric metric : checker.getMonitoredMetrics()) {
        metricNames.add(metric.getMetricName());
    }
    this.buffer = new StringWriterProxy();
    this.writer = new MetricsWriterImpl(new FilteredMetricsExporter(buffer, metricNames), metricsService.getContextNames(), metricsService::getContext);
    return new HealthCheckMicroProfileMetricstExecutionOptions(Boolean.valueOf(checker.getEnabled()), Long.parseLong(checker.getTime()), asTimeUnit(checker.getUnit()), Boolean.valueOf(checker.getAddToMicroProfileHealth()), checker.getMonitoredMetrics());
}
Also used : FilteredMetricsExporter(fish.payara.microprofile.metrics.writer.FilteredMetricsExporter) MetricsWriterImpl(fish.payara.microprofile.metrics.writer.MetricsWriterImpl) HashSet(java.util.HashSet) MonitoredMetric(fish.payara.nucleus.healthcheck.configuration.MonitoredMetric)

Example 2 with MetricsWriterImpl

use of fish.payara.microprofile.metrics.writer.MetricsWriterImpl in project Payara by payara.

the class MetricsResource method getOutputWriter.

@SuppressWarnings("resource")
private static MetricsWriter getOutputWriter(HttpServletRequest request, HttpServletResponse response, MetricsService service, String contentType) throws IOException {
    Writer writer = response.getWriter();
    String method = request.getMethod();
    if (GET.equalsIgnoreCase(method)) {
        if (APPLICATION_JSON.equals(contentType)) {
            return new MetricsWriterImpl(new JsonExporter(writer, Mode.GET, true), service.getContextNames(), service::getContext, getGlobalTags());
        }
        if (TEXT_PLAIN.equals(contentType)) {
            return new MetricsWriterImpl(new OpenMetricsExporter(writer), service.getContextNames(), service::getContext, getGlobalTags());
        }
    }
    if (OPTIONS.equalsIgnoreCase(method)) {
        if (APPLICATION_JSON.equals(contentType)) {
            return new MetricsWriterImpl(new JsonExporter(writer, Mode.OPTIONS, true), service.getContextNames(), service::getContext, getGlobalTags());
        }
    }
    return null;
}
Also used : MetricsWriterImpl(fish.payara.microprofile.metrics.writer.MetricsWriterImpl) OpenMetricsExporter(fish.payara.microprofile.metrics.writer.OpenMetricsExporter) JsonExporter(fish.payara.microprofile.metrics.writer.JsonExporter) MetricsWriter(fish.payara.microprofile.metrics.writer.MetricsWriter) Writer(java.io.Writer)

Aggregations

MetricsWriterImpl (fish.payara.microprofile.metrics.writer.MetricsWriterImpl)2 FilteredMetricsExporter (fish.payara.microprofile.metrics.writer.FilteredMetricsExporter)1 JsonExporter (fish.payara.microprofile.metrics.writer.JsonExporter)1 MetricsWriter (fish.payara.microprofile.metrics.writer.MetricsWriter)1 OpenMetricsExporter (fish.payara.microprofile.metrics.writer.OpenMetricsExporter)1 MonitoredMetric (fish.payara.nucleus.healthcheck.configuration.MonitoredMetric)1 Writer (java.io.Writer)1 HashSet (java.util.HashSet)1