Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class PrometheusExporterServerImpl extends ManagerBase implements PrometheusExporterServer, Configurable {
Expand Down Expand Up @@ -57,11 +58,21 @@ public void handle(final HttpExchange httpExchange) throws IOException {
response = prometheusExporter.getMetrics();
responseCode = 200;
}
httpExchange.getResponseHeaders().set("content-type", "text/plain");
httpExchange.sendResponseHeaders(responseCode, response.length());
byte[] bytesToOutput = response.getBytes(StandardCharsets.UTF_8);
httpExchange.getResponseHeaders().set("content-type", "text/plain; charset=UTF-8");
httpExchange.sendResponseHeaders(responseCode, bytesToOutput.length);
final OutputStream os = httpExchange.getResponseBody();
os.write(response.getBytes());
os.close();
try {
os.write(bytesToOutput);
} catch (IOException e) {
LOG.error(String.format("could not export Prometheus data due to %s", e.getLocalizedMessage()));
if (LOG.isDebugEnabled()) {
LOG.debug("Error during Prometheus export: ", e);
}
os.write("The system could not export Prometheus due to an internal error. Contact your operator to learn about the reason.".getBytes());
} finally {
os.close();
}
}
}

Expand Down