metrics v0.1.1 ExMetrics.FunctionTimer View Source

The Elixir.ExMetrics.FunctionTimer module provides a way to easily time functions and send metrics to a StatsD server, with out having to manually time each function.

Link to this section Summary

Functions

The metric_name/2 function is responsible for fetching the metric name for the function being timed. A custom metric name can be set by setting a @metric_name module attribute above the function, otherwise, a default metric name is used

The metric_options/2 function is responsible for fetching the metric options for the function being timed. Custom metric options can be set by setting a @metric_options module attribute above the function, otherwise, default metric options are used

The timing_function/1 function is used to determine whether to make a call to ExMetrics.histogram/3 or ExMetrics.timing/3. By default, ExMetrics.timing/3 will be called, but this can be overriden with

Link to this section Functions

Link to this macro

deftimed(head, body \\ nil) View Source (macro)

Link to this function

metric_name(module, function_id) View Source

The metric_name/2 function is responsible for fetching the metric name for the function being timed. A custom metric name can be set by setting a @metric_name module attribute above the function, otherwise, a default metric name is used.

If the default metric name is used, it is set as a module attribute, with the name "#{function_id}_metric_name".

If a custom metric name is set with @metric_name, the name is moved to the "#{function_id}_metric_name" module attribute, and @metric_name is set to nil so that it can be overwritten further down in the file.

Link to this function

metric_options(module, function_id) View Source

The metric_options/2 function is responsible for fetching the metric options for the function being timed. Custom metric options can be set by setting a @metric_options module attribute above the function, otherwise, default metric options are used.

If the default metric options are used, they are set as a module attribute, with the name "#{function_id}_metric_options".

If custom metric options are set with @metric_options, the options are moved to the "#{function_id}_metric_options" module attribute, and @metric_options is set to nil so that it can be overwritten further down in the file.

The timing_function/1 function is used to determine whether to make a call to ExMetrics.histogram/3 or ExMetrics.timing/3. By default, ExMetrics.timing/3 will be called, but this can be overriden with:

defmodule UseHistogram do use ExMetrics.FunctionTimer, use_histogram: true end