#include "ShellLatencyServer.h" #include "lib/utils/TimeStamp.h" namespace bts { namespace metrics { ShellLatencyServer::ShellLatencyServer(bts::api::ServiceContext& ctx, metrics::MetricsContainer& mc, utils::Dispatcher& d) : ShellLatencyServiceBase(ctx), _counter(0), _pub(make_clock_stateful_publisher()), _timer(utils::DispatcherTimer(d, 1000, [=]() { tick(); })), _mc(mc), _metrics() { _timer.start(); } ShellLatencyServer::~ShellLatencyServer(){} // This happens on the Dispatcher thread void ShellLatencyServer::tick() { _counter++; Tick t; t.set_key(_counter); t.set_timestamp(utils::TimeStamp::now().to_uint64()); _pub.add_or_update(t); _pub.erase(_counter - 1); _pub.flush(); } // This happens on the quickbus thread void ShellLatencyServer::report( const ::bts::metrics::Report& request, const api::Response<::bts::api::VoidMessage>& reply) { reply(bts::api::VoidMessage()); // look up or create the metric auto key = request.host_name() + "-" + request.version(); auto iter = _metrics.find(key); std::shared_ptr metric; // report at least 1ms because the metric will not report anything if it's 0 auto delta = std::max(1l, (utils::TimeStamp::now() - utils::TimeStamp(request.timestamp())).milliseconds()); if (iter == _metrics.end()) { // create metric auto metric = std::make_shared("spark_shell_latency", std::vector