Search in sources :

Example 1 with PrometheusWriter

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

the class MetricsResource method getOutputWriter.

private MetricsWriter getOutputWriter(HttpServletRequest request, HttpServletResponse response) throws IOException {
    MetricsWriter outputWriter = null;
    String method = request.getMethod();
    Writer writer = response.getWriter();
    String accept = request.getHeader(ACCEPT);
    if (accept == null) {
        accept = TEXT_PLAIN;
    }
    if (GET.equals(method)) {
        if (accept.contains(APPLICATION_JSON)) {
            outputWriter = new JsonMetricWriter(writer);
        } else if (accept.contains(TEXT_PLAIN)) {
            outputWriter = new PrometheusWriter(writer);
        } else {
            outputWriter = new PrometheusWriter(writer);
        }
    } else if (OPTIONS.equals(method)) {
        if (accept.contains(APPLICATION_JSON)) {
            outputWriter = new JsonMetadataWriter(writer);
        } else {
            response.sendError(SC_NOT_ACCEPTABLE, String.format("[%s] not acceptable", accept));
        }
    } else {
        response.sendError(SC_METHOD_NOT_ALLOWED, String.format("HTTP method [%s] not allowed", method));
    }
    return outputWriter;
}
Also used : MetricsWriter(fish.payara.microprofile.metrics.writer.MetricsWriter) PrometheusWriter(fish.payara.microprofile.metrics.writer.PrometheusWriter) JsonMetadataWriter(fish.payara.microprofile.metrics.writer.JsonMetadataWriter) JsonMetricWriter(fish.payara.microprofile.metrics.writer.JsonMetricWriter) MetricsWriter(fish.payara.microprofile.metrics.writer.MetricsWriter) JsonMetadataWriter(fish.payara.microprofile.metrics.writer.JsonMetadataWriter) PrometheusWriter(fish.payara.microprofile.metrics.writer.PrometheusWriter) JsonMetricWriter(fish.payara.microprofile.metrics.writer.JsonMetricWriter) Writer(java.io.Writer)

Aggregations

JsonMetadataWriter (fish.payara.microprofile.metrics.writer.JsonMetadataWriter)1 JsonMetricWriter (fish.payara.microprofile.metrics.writer.JsonMetricWriter)1 MetricsWriter (fish.payara.microprofile.metrics.writer.MetricsWriter)1 PrometheusWriter (fish.payara.microprofile.metrics.writer.PrometheusWriter)1 Writer (java.io.Writer)1