mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-12 10:34:21 +00:00
62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "IServer.h"
|
|
#include "PrometheusMetricsWriter.h"
|
|
|
|
#include <Poco/Net/HTTPServerRequest.h>
|
|
#include <Poco/Net/HTTPServerResponse.h>
|
|
#include <Poco/Net/HTTPRequestHandler.h>
|
|
#include <Poco/Net/HTTPRequestHandlerFactory.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
class PrometheusRequestHandler : public Poco::Net::HTTPRequestHandler
|
|
{
|
|
private:
|
|
IServer & server;
|
|
const PrometheusMetricsWriter & metrics_writer;
|
|
|
|
public:
|
|
explicit PrometheusRequestHandler(IServer & server_, PrometheusMetricsWriter & metrics_writer_)
|
|
: server(server_)
|
|
, metrics_writer(metrics_writer_)
|
|
{
|
|
}
|
|
|
|
void handleRequest(
|
|
Poco::Net::HTTPServerRequest & request,
|
|
Poco::Net::HTTPServerResponse & response) override;
|
|
};
|
|
|
|
|
|
template <typename HandlerType>
|
|
class PrometheusRequestHandlerFactory : public Poco::Net::HTTPRequestHandlerFactory
|
|
{
|
|
private:
|
|
IServer & server;
|
|
std::string endpoint_path;
|
|
PrometheusMetricsWriter metrics_writer;
|
|
|
|
public:
|
|
PrometheusRequestHandlerFactory(IServer & server_, const AsynchronousMetrics & async_metrics_)
|
|
: server(server_)
|
|
, endpoint_path(server_.config().getString("prometheus.endpoint", "/metrics"))
|
|
, metrics_writer(server_.config(), "prometheus", async_metrics_)
|
|
{
|
|
}
|
|
|
|
Poco::Net::HTTPRequestHandler * createRequestHandler(const Poco::Net::HTTPServerRequest & request) override
|
|
{
|
|
if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_GET
|
|
&& request.getURI() == endpoint_path)
|
|
return new HandlerType(server, metrics_writer);
|
|
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
using PrometheusHandlerFactory = PrometheusRequestHandlerFactory<PrometheusRequestHandler>;
|
|
|
|
}
|