Add HistogramMetric type
This commit is contained in:
1 parent
1558b79c16
commit
03864caa09
4 files changed
+115
-14
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include "lib/api/apigateway.pb.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/os/os.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
|
||||
#include <websocketpp/config/asio_no_tls.hpp>
|
||||
#include <websocketpp/server.hpp>
|
||||
@@ -49,9 +50,10 @@ namespace http {
|
||||
std::string _www;
|
||||
std::string _conf;
|
||||
const api::ServiceContext& _ctx;
|
||||
const metrics::MetricsContainer& _metrics;
|
||||
metrics::MetricsContainer& _metrics;
|
||||
std::shared_ptr<metrics::HistogramMetric<4>> _mtimer;
|
||||
|
||||
ServerState(const api::ServiceContext& ctx, const metrics::MetricsContainer& metrics, int port) :
|
||||
ServerState(const api::ServiceContext& ctx, metrics::MetricsContainer& metrics, int port) :
|
||||
_m(),
|
||||
_dispatcher(utils::Dispatcher::get_named("Webserver")),
|
||||
_session(),
|
||||
@@ -59,11 +61,15 @@ namespace http {
|
||||
_port(port),
|
||||
_www(),
|
||||
_ctx(ctx),
|
||||
_metrics(metrics)
|
||||
_metrics(metrics),
|
||||
_mtimer(std::make_shared<metrics::HistogramMetric<4>>("spark_metrics_query_duration_us",
|
||||
std::array<double,4>({ 10.0, 20.0, 40.0, 80.0 })))
|
||||
{
|
||||
_www = os::sparkdata_path("www");
|
||||
_conf = os::sparkdata_path("conf");
|
||||
|
||||
_metrics.publish(_mtimer);
|
||||
|
||||
_server.init_asio(_dispatcher.io_service());
|
||||
_server.set_open_handler(bind(&ServerState::on_open, this, ::_1));
|
||||
_server.set_close_handler(bind(&ServerState::on_close, this, ::_1));
|
||||
@@ -142,10 +148,12 @@ namespace http {
|
||||
}
|
||||
|
||||
void return_metrics(connection_ptr& con) {
|
||||
utils::TimeStamp start = utils::TimeStamp::now();
|
||||
std::stringstream ss;
|
||||
_metrics.print(ss);
|
||||
con->set_body(ss.str());
|
||||
con->set_status(websocketpp::http::status_code::ok);
|
||||
_mtimer->observe((utils::TimeStamp::now() - start).microseconds());
|
||||
}
|
||||
|
||||
void directory_index(connection_ptr& con, const std::string& resource, const boost::filesystem::path& path) {
|
||||
|
||||
Reference in new issue
Block a user