io.prometheus.metrics.exporter.httpserver.HealthyHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmx_prometheus_httpserver Show documentation
Show all versions of jmx_prometheus_httpserver Show documentation
See https://github.com/prometheus/jmx_exporter/blob/master/README.md
package io.prometheus.metrics.exporter.httpserver;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
/**
* Handler for the /-/healthy endpoint
*/
public class HealthyHandler implements HttpHandler {
private final byte[] responseBytes;
private final String contentType;
public HealthyHandler() {
String responseString = "Exporter is healthy.\n";
this.responseBytes = responseString.getBytes(StandardCharsets.UTF_8);
this.contentType = "text/plain; charset=utf-8";
}
@Override
public void handle(HttpExchange exchange) throws IOException {
try {
exchange.getResponseHeaders().set("Content-Type", contentType);
exchange.getResponseHeaders().set("Content-Length", Integer.toString(responseBytes.length));
exchange.sendResponseHeaders(200, responseBytes.length);
exchange.getResponseBody().write(responseBytes);
} finally {
exchange.close();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy