Metrics

class mogwai.metrics.manager.MetricManager

Manages your Metric Agents

Properly inject mogwai metrics, while still allowing custom app metrics

count_calls(fn)

Decorator to track the number of times a function is called.

Parameters:fn (C{func}) – the function to be decorated
Returns:the decorated function
Return type:C{func}
counters(key=None)

Yield Metric Reporter Counters

Parameters:key (basestring) – The metric key to use
hist_calls(fn)

Decorator to check the distribution of return values of a function.

Parameters:fn (C{func}) – the function to be decorated
Returns:the decorated function
Return type:C{func}
histograms(key=None)

Yield Metric Reporter Histograms

Parameters:key (basestring) – The metric key to use
meter_calls(fn)

Decorator to the rate at which a function is called.

Parameters:fn (C{func}) – the function to be decorated
Returns:the decorated function
Return type:C{func}
meters(key=None)

Yield Metric Reporter Meters

Parameters:key (basestring) – The metric key to use
setup_reporters(metric_reporters)

Setup the Metric Reporter(s) for the MetricManager

start()

Start the Metric Reporter

stop()

Stop the Metric Reporter

time_calls(fn)

Decorator to time the execution of the function.

Parameters:fn (C{func}) – the function to be decorated
Returns:the decorated function
Return type:C{func}
timers(key=None)

Yield Metric Reporter Timers

Parameters:key (basestring) – The metric key to use
exception mogwai.metrics.manager.MogwaiMetricsException

Exception thrown when a metric system error occurs

args
message
class mogwai.metrics.base.MetricsRegistry(clock=<built-in function time>)

A single interface used to gather metrics on a service. It keeps track of all the relevant Counters, Meters, Histograms, and Timers. It does not have a reference back to its service. The service would create a L{MetricsRegistry} to manage all of its metrics tools.

clear()
counter(key)

Gets a counter based on a key, creates a new one if it does not exist.

@param key: name of the metric @type key: C{str}

@return: L{Counter}

dump_metrics()

Formats all of the metrics and returns them as a dict.

@return: C{list} of C{dict} of metrics

gauge(key, gauge=None)
get_metrics(key)

Gets all the metrics for a specified key.

@param key: name of the metric @type key: C{str}

@return: C{dict}

histogram(key)

Gets a histogram based on a key, creates a new one if it does not exist.

@param key: name of the metric @type key: C{str}

@return: L{Histogram}

meter(key)

Gets a meter based on a key, creates a new one if it does not exist.

@param key: name of the metric @type key: C{str}

@return: L{Meter}

timer(key)

Gets a timer based on a key, creates a new one if it does not exist.

@param key: name of the metric @type key: C{str}

@return: L{Timer}

class mogwai.metrics.base.RegexRegistry(pattern=None, clock=<built-in function time>)

A single interface used to gather metrics on a service. This class uses a regex to combine measures that match a pattern. For example, if you have a REST API, instead of defining a timer for each method, you can use a regex to capture all API calls and group them. A pattern like ‘^/api/(?P<model>)/d+/(?P<verb>)?$’ will group and measure the following:

/api/users/1 -> users /api/users/1/edit -> users/edit /api/users/2/edit -> users/edit
clear()
counter(key)
dump_metrics()

Formats all of the metrics and returns them as a dict.

@return: C{list} of C{dict} of metrics

gauge(key, gauge=None)
get_metrics(key)

Gets all the metrics for a specified key.

@param key: name of the metric @type key: C{str}

@return: C{dict}

histogram(key)
meter(key)
timer(key)
exception mogwai.metrics.base.MogwaiMetricsException

Exception thrown when a metric system error occurs

args
message
class mogwai.metrics.base.BaseMetricsReporter(registry=None, reportingInterval=300, metric_prefix=None)

Base Metrics Reporter class

Customize this class for the specific metrics service, ie. Graphite, NewRelic, etc.

get_metrics(timestamp=None, *args, **kwargs)

Default pyformance implementation to collect all the metrics from the registries.

Change this if you wan’t customize for a particular metric collection system, ie. graphite, newrelic, etc.

Parameters:timestamp (long | int) – use this timestamp instead of the generated timestamp when the method is run
Returns:Timestamp and aggregated metrics from all registries.
Return type:tuple( long | int, dict )
send_metrics(*args, **kwargs)

Default pyformance implementation is to dump all metrics to STDOUT

Change this if you want to customize for a particular metric collection system, ie. graphite, newrelic, etc.

setup_registry(registry=None)

Setup the Metric Reporter with the given registry(s)

start()

Start the Metric Reporter

start_reporter(reportingInterval)

Start the Metric Reporter Agent

Kicks off a loop that every reportingInterval runs the send_metrics method.

Parameters:reportingInterval (float | long | int) – The interval (number of seconds) on which to report the collected metrics.
stop()

Stop the Metric Reporter

mogwai.metrics.base.ConsoleMetricReporter

alias of BaseMetricsReporter