18 #include <boost/algorithm/string/join.hpp>
19 #include <boost/bind.hpp>
20 #include <boost/mem_fn.hpp>
21 #include <boost/math/special_functions/fpclassify.hpp>
22 #include <gutil/strings/substitute.h>
23 #include <rapidjson/stringbuffer.h>
24 #include <rapidjson/prettywriter.h>
31 using namespace impala;
32 using namespace rapidjson;
33 using namespace strings;
39 Document* document, Value* out_val) {
40 Value val(value.c_str(), document->GetAllocator());
47 Value
name(key_.c_str(), document->GetAllocator());
48 val->AddMember(
"name",
name, document->GetAllocator());
49 Value desc(description_.c_str(), document->GetAllocator());
50 val->AddMember(
"description", desc, document->GetAllocator());
51 Value metric_value(ToHumanReadable().c_str(), document->GetAllocator());
52 val->AddMember(
"human_readable", metric_value, document->GetAllocator());
59 if (webserver != NULL) {
63 default_callback,
false);
77 Webserver::ArgumentMap::const_iterator metric_name = args.find(
"metric");
78 lock_guard<mutex> l(
lock_);
79 if (metric_name != args.end()) {
80 MetricMap::const_iterator metric =
metric_map_.find(metric_name->second);
82 metric->second->ToLegacyJson(document);
87 stack<MetricGroup*> groups;
89 while (!groups.empty()) {
94 BOOST_FOREACH(
const ChildGroupMap::value_type& child, group->
children_) {
95 groups.push(child.second);
97 BOOST_FOREACH(
const MetricMap::value_type& m, group->
metric_map_) {
98 m.second->ToLegacyJson(document);
104 Document* document) {
105 Webserver::ArgumentMap::const_iterator metric_group = args.find(
"metric_group");
106 lock_guard<mutex> l(
lock_);
109 if (metric_group == args.end()) {
111 ToJson(
true, document, &container);
112 document->AddMember(
"metric_group", container, document->GetAllocator());
119 stack<MetricGroup*> groups;
121 while (!groups.empty() && found_group == NULL) {
126 BOOST_FOREACH(
const ChildGroupMap::value_type& child, group->
children_) {
127 if (child.first == metric_group->second) {
128 found_group = child.second;
131 groups.push(child.second);
134 if (found_group != NULL) {
136 found_group->
ToJson(
false, document, &container);
137 document->AddMember(
"metric_group", container, document->GetAllocator());
139 Value error(Substitute(
"Metric group $0 not found", metric_group->second).c_str(),
140 document->GetAllocator());
141 document->AddMember(
"error", error, document->GetAllocator());
146 Value metric_list(kArrayType);
147 BOOST_FOREACH(
const MetricMap::value_type& m,
metric_map_) {
149 m.second->ToJson(document, &metric_value);
150 metric_list.PushBack(metric_value, document->GetAllocator());
153 Value container(kObjectType);
154 container.AddMember(
"metrics", metric_list, document->GetAllocator());
155 container.AddMember(
"name",
name_.c_str(), document->GetAllocator());
156 if (include_children) {
157 Value child_groups(kArrayType);
158 BOOST_FOREACH(
const ChildGroupMap::value_type& child,
children_) {
160 child.second->ToJson(
true, document, &child_value);
161 child_groups.PushBack(child_value, document->GetAllocator());
163 container.AddMember(
"child_groups", child_groups, document->GetAllocator());
166 *out_val = container;
170 lock_guard<mutex> l(
lock_);
171 ChildGroupMap::iterator it =
children_.find(name);
172 if (it !=
children_.end())
return it->second;
181 document.SetObject();
184 PrettyWriter<StringBuffer> writer(strbuf);
185 document.Accept(writer);
186 return strbuf.GetString();
void ToJsonValue< string >(const string &value, const TUnit::type unit, Document *document, Value *out_val)
boost::scoped_ptr< ObjectPool > obj_pool_
Pool containing all metric objects.
void AddStandardFields(rapidjson::Document *document, rapidjson::Value *val)
boost::function< void(const ArgumentMap &args, rapidjson::Document *json)> UrlCallback
boost::scoped_ptr< ObjectPool > obj_pool_
Object pool owned by the coordinator. Any executor will have its own pool.
MetricGroup(const std::string &name)
MetricGroup * GetChildGroup(const std::string &name)
Creates or returns an already existing child metric group.
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.
Status Init(Webserver *webserver)
std::map< std::string, std::string > ArgumentMap
const std::string & name() const
std::string DebugString()
Useful for debuggers, returns the output of CMCompatibleCallback().
void TemplateCallback(const Webserver::ArgumentMap &args, rapidjson::Document *document)
std::string name_
Name of this metric group.
void ToJson(bool include_children, rapidjson::Document *document, rapidjson::Value *out_val)
Converts this metric group (and optionally all of its children recursively) to JSON.
void CMCompatibleCallback(const Webserver::ArgumentMap &args, rapidjson::Document *document)
boost::mutex lock_
Guards metric_map_ and children_.