1#include "PrometheusRequestHandler.h"
2
3#include <IO/HTTPCommon.h>
4
5#include <Common/Exception.h>
6
7#include <Poco/Net/HTTPServerRequest.h>
8#include <Poco/Net/HTTPServerResponse.h>
9
10#include <Common/ProfileEvents.h>
11#include <Common/CurrentMetrics.h>
12
13#include <IO/WriteBufferFromHTTPServerResponse.h>
14
15
16namespace DB
17{
18
19void PrometheusRequestHandler::handleRequest(
20 Poco::Net::HTTPServerRequest & request,
21 Poco::Net::HTTPServerResponse & response)
22{
23 try
24 {
25 const auto & config = server.config();
26 unsigned keep_alive_timeout = config.getUInt("keep_alive_timeout", 10);
27
28 setResponseDefaultHeaders(response, keep_alive_timeout);
29
30 response.setContentType("text/plain; version=0.0.4; charset=UTF-8");
31
32 auto wb = WriteBufferFromHTTPServerResponse(request, response, keep_alive_timeout);
33 metrics_writer.write(wb);
34 wb.finalize();
35 }
36 catch (...)
37 {
38 tryLogCurrentException("PrometheusRequestHandler");
39 }
40}
41
42}
43