Commit ad1596aa authored by zhujiashun's avatar zhujiashun

add DumpPrometheusMetricsToIOBuf

parent 6aa2d593
......@@ -22,6 +22,7 @@
#include "brpc/closure_guard.h" // ClosureGuard
#include "brpc/builtin/prometheus_metrics_service.h"
#include "brpc/builtin/common.h"
#include "brpc/details/server_private_accessor.h"
#include "bvar/bvar.h"
namespace bvar {
......@@ -181,14 +182,21 @@ void PrometheusMetricsService::default_method(::google::protobuf::RpcController*
ClosureGuard done_guard(done);
Controller *cntl = static_cast<Controller*>(cntl_base);
cntl->http_response().set_content_type("text/plain");
if (DumpPrometheusMetricsToIOBuf(_server, &cntl->response_attachment()) != 0) {
cntl->SetFailed("Fail to dump metrics");
return;
}
}
int DumpPrometheusMetricsToIOBuf(const Server* server, butil::IOBuf* output) {
butil::IOBufBuilder os;
PrometheusMetricsDumper dumper(&os, _server->ServerPrefix());
PrometheusMetricsDumper dumper(&os, brpc::ServerPrivateAccessor(server).ServerPrefix());
const int ndump = bvar::Variable::dump_exposed(&dumper, NULL);
if (ndump < 0) {
cntl->SetFailed("Fail to dump metrics");
return;
return -1;
}
os.move_to(cntl->response_attachment());
os.move_to(*output);
return 0;
}
} // namespace brpc
......@@ -31,10 +31,13 @@ public:
const ::brpc::MetricsRequest* request,
::brpc::MetricsResponse* response,
::google::protobuf::Closure* done) override;
private:
Server* _server;
};
int DumpPrometheusMetricsToIOBuf(const Server* server, butil::IOBuf* output);
} // namepace brpc
#endif // BRPC_PROMETHEUS_METRICS_SERVICE_H
......@@ -97,6 +97,8 @@ public:
RestfulMap* global_restful_map() const
{ return _server->_global_restful_map; }
std::string ServerPrefix() const { return _server->ServerPrefix(); }
private:
const Server* _server;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment