Metric for latency between spark shell and server

This commit is contained in:
Eric Harding committed 2018-06-28 11:07:45 -04:00
1 parent 03eff1f388
commit 3da1bfaeb1
8 files changed
+185 -3

No files matched your search

@@ -0,0 +1,57 @@
#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, 2500, [=]() { 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<AutoResetMetric> metric;
auto delta = (utils::TimeStamp::now() - utils::TimeStamp(request.timestamp())).milliseconds();
if (iter == _metrics.end()) {
// create metric
auto metric = std::make_shared<AutoResetMetric>("spark_shell_latency", std::vector<Label>({{"shell",key}}));
_metrics.insert(std::make_pair(key, metric));
metric->max(delta);
_mc.publish(metric);
}
else {
iter->second->max(delta);
}
}
}}