2019-11-24 12:06:10 +00:00
|
|
|
#include "PrometheusRequestHandler.h"
|
|
|
|
|
|
|
|
#include <IO/HTTPCommon.h>
|
|
|
|
|
|
|
|
#include <Common/Exception.h>
|
|
|
|
|
|
|
|
#include <Poco/Net/HTTPServerRequest.h>
|
|
|
|
#include <Poco/Net/HTTPServerResponse.h>
|
2020-05-27 17:52:52 +00:00
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
2019-11-24 12:06:10 +00:00
|
|
|
|
|
|
|
#include <Common/ProfileEvents.h>
|
|
|
|
#include <Common/CurrentMetrics.h>
|
|
|
|
|
|
|
|
#include <IO/WriteBufferFromHTTPServerResponse.h>
|
2020-06-12 16:15:02 +00:00
|
|
|
#include <Server/HTTPHandlerRequestFilter.h>
|
2019-11-24 12:06:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
void PrometheusRequestHandler::handleRequest(
|
|
|
|
Poco::Net::HTTPServerRequest & request,
|
|
|
|
Poco::Net::HTTPServerResponse & response)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto & config = server.config();
|
|
|
|
unsigned keep_alive_timeout = config.getUInt("keep_alive_timeout", 10);
|
|
|
|
|
|
|
|
setResponseDefaultHeaders(response, keep_alive_timeout);
|
|
|
|
|
|
|
|
response.setContentType("text/plain; version=0.0.4; charset=UTF-8");
|
|
|
|
|
|
|
|
auto wb = WriteBufferFromHTTPServerResponse(request, response, keep_alive_timeout);
|
2019-11-24 20:03:09 +00:00
|
|
|
metrics_writer.write(wb);
|
2019-11-24 12:06:10 +00:00
|
|
|
wb.finalize();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
tryLogCurrentException("PrometheusRequestHandler");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 16:15:02 +00:00
|
|
|
Poco::Net::HTTPRequestHandlerFactory * createPrometheusHandlerFactory(IServer & server, AsynchronousMetrics & async_metrics, const std::string & config_prefix)
|
2020-06-12 10:04:42 +00:00
|
|
|
{
|
2020-06-12 16:15:02 +00:00
|
|
|
return addFiltersFromConfig(new HandlingRuleHTTPHandlerFactory<PrometheusRequestHandler>(
|
|
|
|
server, PrometheusMetricsWriter(server.config(), config_prefix + ".handler", async_metrics)), server.config(), config_prefix);
|
2020-06-12 10:04:42 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 12:06:10 +00:00
|
|
|
}
|