17 #include <boost/bind.hpp>
18 #include <boost/scoped_ptr.hpp>
19 #include <boost/foreach.hpp>
20 #include <gutil/strings/substitute.h>
29 using namespace impala;
30 using namespace rapidjson;
31 using namespace strings;
69 if (webserver != NULL) {
81 DCHECK(event_handler != NULL);
82 lock_guard<mutex> l(
lock_);
83 event_handlers_.push_back(event_handler);
88 lock_guard<mutex> l(
lock_);
89 Value servers(kArrayType);
91 Value server(kObjectType);
92 handler->
ToJson(&server, document);
93 servers.PushBack(server, document->GetAllocator());
95 document->AddMember(
"servers", servers, document->GetAllocator());
100 Webserver::ArgumentMap::const_iterator server_it = args.find(
"server");
101 bool reset_all_servers = (server_it == args.end());
102 Webserver::ArgumentMap::const_iterator method_it = args.find(
"method");
103 bool reset_all_in_server = (method_it == args.end());
104 lock_guard<mutex> l(
lock_);
106 if (reset_all_servers || handler->
server_name() == server_it->second) {
107 if (reset_all_in_server) {
110 handler->
Reset(method_it->second);
112 if (!reset_all_servers)
return;
118 lock_guard<mutex> l(method_map_lock_);
119 MethodMap::iterator it = method_map_.find(method_name);
120 if (it == method_map_.end())
return;
121 it->second->time_stats->Reset();
122 it->second->num_in_flight = 0L;
126 lock_guard<mutex> l(method_map_lock_);
127 BOOST_FOREACH(
const MethodMap::value_type& method, method_map_) {
128 method.second->time_stats->Reset();
129 method.second->num_in_flight = 0L;
134 server_name_(server_name), metrics_(metrics) {
141 server->AddMember(
"name",
name, document->GetAllocator());
142 Value methods(kArrayType);
143 BOOST_FOREACH(
const MethodMap::value_type& rpc,
method_map_) {
144 Value method(kObjectType);
145 Value method_name(rpc.first.c_str(), document->GetAllocator());
146 method.AddMember(
"name", method_name, document->GetAllocator());
147 const string& human_readable = rpc.second->time_stats->ToHumanReadable();
148 Value summary(human_readable.c_str(), document->GetAllocator());
149 method.AddMember(
"summary", summary, document->GetAllocator());
150 method.AddMember(
"in_flight", rpc.second->num_in_flight, document->GetAllocator());
152 method.AddMember(
"server_name",
server_name, document->GetAllocator());
153 methods.PushBack(method, document->GetAllocator());
155 server->AddMember(
"methods", methods, document->GetAllocator());
161 MethodMap::iterator it;
168 const string& time_metric_name =
169 Substitute(
"rpc-method.$0.$1.call_duration",
server_name_, descriptor->
name);
172 it =
method_map_.insert(make_pair(descriptor->
name, descriptor)).first;
175 ++(it->second->num_in_flight);
179 VLOG_RPC <<
"RPC call: " << string(fn_name) <<
"(from "
181 return reinterpret_cast<void*
>(ctxt_ptr);
187 const string& call_name = string(fn_name);
boost::mutex method_map_lock_
Protects method_map_ and rpc_counter_.
boost::function< void(const ArgumentMap &args, rapidjson::Document *json)> UrlCallback
MetricGroup * metrics_
Metrics subsystem access.
M * RegisterMetric(M *metric)
boost::mutex lock_
protects all fields below
MetricGroups may be organised hierarchically as a tree.
void RegisterUrlCallback(const std::string &path, const std::string &template_filename, const UrlCallback &callback, bool is_on_nav_bar=true)
Only one callback may be registered per URL.
const ThriftServer::ConnectionContext * cnxn_ctx
TNetworkAddress network_address
void ResetCallback(const Webserver::ArgumentMap &args, Document *document)
void RegisterEventHandler(RpcEventHandler *event_handler)
static std::string Print(bool value, TUnit::type ignored, bool verbose=false)
std::map< std::string, std::string > ArgumentMap
void ResetAll()
Resets the statistics for all methods.
vector< RpcEventHandler * > event_handlers_
void Reset(const std::string &method_name)
Resets the statistics for a single method.
scoped_ptr< RpcEventHandlerManager > handler_manager
std::string server_name_
Name of the server that we listen for events from.
Created per-Rpc invocation.
void JsonCallback(const Webserver::ArgumentMap &args, Document *document)
Per-connection information.
void InitRpcEventTracing(Webserver *webserver)
Initialises rpc event tracing, must be called before any RpcEventHandlers are created.
std::string name
Name of the method.
virtual void * getContext(const char *fn_name, void *server_context)
void Update(const T &value)
int64_t MonotonicMillis()
void JsonCallback(bool always_text, const Webserver::ArgumentMap &args, Document *document)
StatsMetric< double > * time_stats
Summary statistics for the time taken to respond to this method.
void ToJson(rapidjson::Value *server, rapidjson::Document *document)
const int64_t start_time_ms
Monotonic milliseconds (typically boot time) when the call started.
virtual void postWrite(void *ctx, const char *fn_name, uint32_t bytes)
MethodMap method_map_
Map of all methods, populated lazily as they are invoked for the first time.
std::string server_name() const
MethodDescriptor * method_descriptor
Pointer to parent MethodDescriptor, to save a lookup on deletion.
AtomicInt< uint32_t > num_in_flight
Number of invocations in flight.
RpcEventHandler(const std::string &server_name, MetricGroup *metrics)