Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::SimpleMetric< T, metric_kind > Class Template Reference

#include <metrics.h>

Inheritance diagram for impala::SimpleMetric< T, metric_kind >:
Collaboration diagram for impala::SimpleMetric< T, metric_kind >:

Public Member Functions

 SimpleMetric (const std::string &key, const TUnit::type unit, const T &initial_value, const std::string &description="")
 
 SimpleMetric (const std::string &key, const TUnit::type unit, const std::string &description="")
 
virtual ~SimpleMetric ()
 
value ()
 Returns the current value, updating it if necessary. Thread-safe. More...
 
void set_value (const T &value)
 Sets the current value. Thread-safe. More...
 
void Increment (const T &delta)
 Adds 'delta' to the current value atomically. More...
 
virtual void ToJson (rapidjson::Document *document, rapidjson::Value *val)
 name, value, human_readable, description More...
 
virtual std::string ToHumanReadable ()
 
virtual void ToLegacyJson (rapidjson::Document *document)
 This method is kept for backwards-compatibility with CM5.0. More...
 
const TUnit::type unit () const
 
const TMetricKind::type kind () const
 
const std::string & key () const
 
const std::string & description () const
 

Protected Member Functions

virtual void CalculateValue ()
 
void AddStandardFields (rapidjson::Document *document, rapidjson::Value *val)
 

Protected Attributes

const TUnit::type unit_
 Units of this metric. More...
 
boost::mutex lock_
 Guards access to value_. More...
 
value_
 The current value of the metric. More...
 
const std::string key_
 Unique key identifying this metric. More...
 
const std::string description_
 

Detailed Description

template<typename T, TMetricKind::type metric_kind = TMetricKind::GAUGE>
class impala::SimpleMetric< T, metric_kind >

A SimpleMetric has a value which is a simple primitive type: e.g. integers, strings and floats. It is parameterised not only by the type of its value, but by both the unit (e.g. bytes/s), drawn from TUnit and the 'kind' of the metric itself. The kind can be one of: 'gauge', which may increase or decrease over time, a 'counter' which is increasing only over time, or a 'property' which is not numeric. SimpleMetrics return their current value through the value() method. Access to value() is thread-safe. TODO: We can use type traits to select a more efficient lock-free implementation of value() etc. where it is safe to do so.

Definition at line 104 of file metrics.h.

Constructor & Destructor Documentation

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
impala::SimpleMetric< T, metric_kind >::SimpleMetric ( const std::string &  key,
const TUnit::type  unit,
const T &  initial_value,
const std::string &  description = "" 
)
inline

Definition at line 106 of file metrics.h.

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
impala::SimpleMetric< T, metric_kind >::SimpleMetric ( const std::string &  key,
const TUnit::type  unit,
const std::string &  description = "" 
)
inline

Definition at line 111 of file metrics.h.

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
virtual impala::SimpleMetric< T, metric_kind >::~SimpleMetric ( )
inlinevirtual

Definition at line 115 of file metrics.h.

Member Function Documentation

void Metric::AddStandardFields ( rapidjson::Document *  document,
rapidjson::Value *  val 
)
protectedinherited

Convenience method to add standard fields (name, description, human readable string) to 'val'.

Definition at line 46 of file metrics.cc.

References impala::name.

Referenced by impala::SetMetric< std::string >::ToJson(), impala::StatsMetric< double >::ToJson(), and impala::SimpleMetric< T, metric_kind >::ToJson().

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
virtual void impala::SimpleMetric< T, metric_kind >::CalculateValue ( )
inlineprotectedvirtual

Called to compute value_ if necessary during calls to value(). The more natural approach would be to have virtual T value(), but that's not possible in C++. TODO: Should be cheap to have a blank implementation, but if required we can cause the compiler to avoid calling this entirely through a compile-time constant.

Definition at line 175 of file metrics.h.

Referenced by impala::SimpleMetric< T, metric_kind >::value().

const std::string& impala::Metric::description ( ) const
inlineinherited

Definition at line 72 of file metrics.h.

References impala::Metric::description_.

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
void impala::SimpleMetric< T, metric_kind >::Increment ( const T &  delta)
inline
const std::string& impala::Metric::key ( ) const
inlineinherited

Definition at line 71 of file metrics.h.

References impala::Metric::key_.

Referenced by impala::SimpleMetric< T, metric_kind >::Increment().

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
const TMetricKind::type impala::SimpleMetric< T, metric_kind >::kind ( ) const
inline
template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
void impala::SimpleMetric< T, metric_kind >::set_value ( const T &  value)
inline
template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
virtual std::string impala::SimpleMetric< T, metric_kind >::ToHumanReadable ( )
inlinevirtual

Writes a human-readable representation of this metric to 'out'. This is the representation that is often displayed in webpages etc.

Implements impala::Metric.

Definition at line 156 of file metrics.h.

References impala::PrettyPrinter::Print(), impala::SimpleMetric< T, metric_kind >::unit(), and impala::SimpleMetric< T, metric_kind >::value().

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
virtual void impala::SimpleMetric< T, metric_kind >::ToJson ( rapidjson::Document *  document,
rapidjson::Value *  val 
)
inlinevirtual

name, value, human_readable, description

Builds a new Value into 'val', using (if required) the allocator from 'document'. Should set the following fields where appropriate:

Implements impala::Metric.

Definition at line 140 of file metrics.h.

References impala::Metric::AddStandardFields(), impala::SimpleMetric< T, metric_kind >::kind(), impala::PrintTMetricKind(), impala::PrintTUnit(), impala::ToJsonValue(), impala::SimpleMetric< T, metric_kind >::unit(), and impala::SimpleMetric< T, metric_kind >::value().

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
virtual void impala::SimpleMetric< T, metric_kind >::ToLegacyJson ( rapidjson::Document *  document)
inlinevirtual

This method is kept for backwards-compatibility with CM5.0.

Adds a new json value directly to 'document' of the form: "name" : "human-readable-string"

Implements impala::Metric.

Definition at line 160 of file metrics.h.

References impala::Metric::key_, impala::ToJsonValue(), and impala::SimpleMetric< T, metric_kind >::value().

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
const TUnit::type impala::SimpleMetric< T, metric_kind >::unit ( ) const
inline

Member Data Documentation

const std::string impala::Metric::description_
protectedinherited

Description of this metric. TODO: share one copy amongst metrics with the same description.

Definition at line 80 of file metrics.h.

Referenced by impala::Metric::description().

const std::string impala::Metric::key_
protectedinherited
template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
boost::mutex impala::SimpleMetric< T, metric_kind >::lock_
protected
template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
const TUnit::type impala::SimpleMetric< T, metric_kind >::unit_
protected

Units of this metric.

Definition at line 178 of file metrics.h.

Referenced by impala::SimpleMetric< T, metric_kind >::unit().

template<typename T , TMetricKind::type metric_kind = TMetricKind::GAUGE>
T impala::SimpleMetric< T, metric_kind >::value_
protected

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