diff --git a/src/server/sparkd/http/WebServer.cpp b/src/server/sparkd/http/WebServer.cpp index 1fd553db8..bba094524 100644 --- a/src/server/sparkd/http/WebServer.cpp +++ b/src/server/sparkd/http/WebServer.cpp @@ -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 #include @@ -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> _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>("spark_metrics_query_duration_us", + std::array({ 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) { diff --git a/src/server/sparkd/metrics/metrics.cpp b/src/server/sparkd/metrics/metrics.cpp index cb17bd792..678833a7d 100644 --- a/src/server/sparkd/metrics/metrics.cpp +++ b/src/server/sparkd/metrics/metrics.cpp @@ -31,8 +31,24 @@ std::ostream& operator<<(std::ostream& os, const std::vector