Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::MetricGroup Class Reference

MetricGroups may be organised hierarchically as a tree. More...

#include <metrics.h>

Collaboration diagram for impala::MetricGroup:

Public Member Functions

 MetricGroup (const std::string &name)
 
template<typename M >
M * RegisterMetric (M *metric)
 
template<typename T >
SimpleMetric< T > * AddGauge (const std::string &key, const T &value, const TUnit::type unit=TUnit::NONE, const std::string &description="")
 Create a gauge metric object with given key and initial value (owned by this object) More...
 
template<typename T >
SimpleMetric< T,
TMetricKind::PROPERTY > * 
AddProperty (const std::string &key, const T &value, const std::string &description="")
 
template<typename T >
SimpleMetric< T,
TMetricKind::COUNTER > * 
AddCounter (const std::string &key, const T &value, const TUnit::type unit=TUnit::UNIT, const std::string &description="")
 
template<typename M >
M * FindMetricForTesting (const std::string &key)
 Used for testing only. More...
 
Status Init (Webserver *webserver)
 
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. More...
 
MetricGroupGetChildGroup (const std::string &name)
 Creates or returns an already existing child metric group. More...
 
std::string DebugString ()
 Useful for debuggers, returns the output of CMCompatibleCallback(). More...
 
const std::string & name () const
 

Private Types

typedef std::map< std::string,
Metric * > 
MetricMap
 Contains all Metric objects, indexed by key. More...
 
typedef std::map< std::string,
MetricGroup * > 
ChildGroupMap
 All child metric groups. More...
 

Private Member Functions

void TemplateCallback (const Webserver::ArgumentMap &args, rapidjson::Document *document)
 
void CMCompatibleCallback (const Webserver::ArgumentMap &args, rapidjson::Document *document)
 

Private Attributes

boost::scoped_ptr< ObjectPoolobj_pool_
 Pool containing all metric objects. More...
 
std::string name_
 Name of this metric group. More...
 
boost::mutex lock_
 Guards metric_map_ and children_. More...
 
MetricMap metric_map_
 
ChildGroupMap children_
 

Detailed Description

MetricGroups may be organised hierarchically as a tree.

Container for a set of metrics. A MetricGroup owns the memory for every metric contained within it (see Add*() to create commonly used metric types). Metrics are 'registered' with a MetricGroup, once registered they cannot be deleted.Typically a metric object is cached by its creator after registration. If a metric must be retrieved without an available pointer, FindMetricForTesting() will search the MetricGroup and all its descendent MetricGroups in turn. TODO: Hierarchical naming: that is, resolve "group1.group2.metric-name" to a path through the metric tree.

Definition at line 200 of file metrics.h.

Member Typedef Documentation

typedef std::map<std::string, MetricGroup*> impala::MetricGroup::ChildGroupMap
private

All child metric groups.

Definition at line 300 of file metrics.h.

typedef std::map<std::string, Metric*> impala::MetricGroup::MetricMap
private

Contains all Metric objects, indexed by key.

Definition at line 296 of file metrics.h.

Constructor & Destructor Documentation

MetricGroup::MetricGroup ( const std::string &  name)

Definition at line 55 of file metrics.cc.

Member Function Documentation

template<typename T >
SimpleMetric<T, TMetricKind::COUNTER>* impala::MetricGroup::AddCounter ( const std::string &  key,
const T &  value,
const TUnit::type  unit = TUnit::UNIT,
const std::string &  description = "" 
)
inline
template<typename T >
SimpleMetric<T>* impala::MetricGroup::AddGauge ( const std::string &  key,
const T &  value,
const TUnit::type  unit = TUnit::NONE,
const std::string &  description = "" 
)
inline
template<typename T >
SimpleMetric<T, TMetricKind::PROPERTY>* impala::MetricGroup::AddProperty ( const std::string &  key,
const T &  value,
const std::string &  description = "" 
)
inline
void MetricGroup::CMCompatibleCallback ( const Webserver::ArgumentMap args,
rapidjson::Document *  document 
)
private

Legacy webpage callback for CM 5.0 and earlier. Produces a flattened map of (key, value) pairs for all metrics in this hierarchy. If args contains a paramater 'metric', only the json for that metric is returned.

Definition at line 73 of file metrics.cc.

References children_, lock_, and metric_map_.

Referenced by Init().

string MetricGroup::DebugString ( )

Useful for debuggers, returns the output of CMCompatibleCallback().

Definition at line 178 of file metrics.cc.

References TemplateCallback().

template<typename M >
M* impala::MetricGroup::FindMetricForTesting ( const std::string &  key)
inline

Used for testing only.

Returns a metric by key. All MetricGroups reachable from this group are searched in depth-first order, starting with the root group. Returns NULL if there is no metric with that key. This is not a very cheap operation; the result should be cached where possible.

Definition at line 253 of file metrics.h.

References children_, lock_, and metric_map_.

Referenced by TEST(), and impala::TEST().

MetricGroup * MetricGroup::GetChildGroup ( const std::string &  name)

Creates or returns an already existing child metric group.

Definition at line 169 of file metrics.cc.

References children_, lock_, name(), and obj_pool_.

Referenced by impala::ImpalaServer::ImpalaServer(), impala::RegisterMemoryMetrics(), and impala::TEST().

Status MetricGroup::Init ( Webserver webserver)

Register page callbacks with the webserver. Only the root of any metric group hierarchy needs to do this.

Definition at line 58 of file metrics.cc.

References CMCompatibleCallback(), impala::Status::OK, impala::Webserver::RegisterUrlCallback(), and TemplateCallback().

const std::string& impala::MetricGroup::name ( ) const
inline

Definition at line 283 of file metrics.h.

References name_.

Referenced by GetChildGroup().

template<typename M >
M* impala::MetricGroup::RegisterMetric ( M *  metric)
inline

Registers a new metric. Ownership of the metric will be transferred to this MetricGroup object, so callers should take care not to destroy the Metric they pass in. It is an error to call twice with metrics with the same key. The template parameter M must be a subclass of Metric.

Definition at line 211 of file metrics.h.

References lock_, metric_map_, and obj_pool_.

Referenced by AddCounter(), AddGauge(), AddProperty(), impala::StatestoreSubscriber::AddTopic(), impala::CatalogServer::CatalogServer(), impala::RpcEventHandler::getContext(), impala::JvmMetric::InitMetrics(), impala::RegisterMemoryMetrics(), impala::RequestPoolService::RequestPoolService(), impala::ResourceBroker::ResourceBroker(), impala::Statestore::Statestore(), impala::StatestoreSubscriber::StatestoreSubscriber(), and impala::TEST().

void MetricGroup::TemplateCallback ( const Webserver::ArgumentMap args,
rapidjson::Document *  document 
)
private

Webserver callback for /metrics. Produces a tree of JSON values, each representing a metric group, and each including a list of metrics, and a list of immediate children. If args contains a paramater 'metric', only the json for that metric is returned.

Definition at line 103 of file metrics.cc.

References children_, lock_, and ToJson().

Referenced by DebugString(), and Init().

void MetricGroup::ToJson ( bool  include_children,
rapidjson::Document *  document,
rapidjson::Value *  out_val 
)

Converts this metric group (and optionally all of its children recursively) to JSON.

Definition at line 145 of file metrics.cc.

References children_, metric_map_, and name_.

Referenced by TemplateCallback(), and impala::TEST().

Member Data Documentation

ChildGroupMap impala::MetricGroup::children_
private
boost::mutex impala::MetricGroup::lock_
private

Guards metric_map_ and children_.

Definition at line 293 of file metrics.h.

Referenced by CMCompatibleCallback(), FindMetricForTesting(), GetChildGroup(), RegisterMetric(), and TemplateCallback().

MetricMap impala::MetricGroup::metric_map_
private

Definition at line 297 of file metrics.h.

Referenced by CMCompatibleCallback(), FindMetricForTesting(), RegisterMetric(), and ToJson().

std::string impala::MetricGroup::name_
private

Name of this metric group.

Definition at line 290 of file metrics.h.

Referenced by name(), and ToJson().

boost::scoped_ptr<ObjectPool> impala::MetricGroup::obj_pool_
private

Pool containing all metric objects.

Definition at line 287 of file metrics.h.

Referenced by GetChildGroup(), and RegisterMetric().


The documentation for this class was generated from the following files: