Elixometer (Elixometer v1.5.0) View Source

A light wrapper around exometer.

Elixometer allows you to define metrics and subscribe them automatically to the default reporter for your environment.

Configuration

In one of your config files, set up an exometer reporter, and then register it to elixometer like this:

 config(:exometer_core, report: [reporters: [{:exometer_report_tty, []}]])
 config(:elixometer, reporter: :exometer_report_tty)

Metrics

Defining metrics in elixometer is substantially easier than in exometer. Instead of defining and then updating a metric, just update it. Also, instead of providing a list of atoms, a metric is named with a period separated bitstring. Presently, Elixometer supports timers, histograms, gauges, and counters.

Timings may also be defined by annotating a function with a @timed annotation. This annotation takes a key argument, which tells elixometer what key to use. You can specify :auto and a key will be generated from the module name and method name.

Updating a metric is similarly easy:

 defmodule ParentModule.MetricsTest do
   use Elixometer

   def counter_test(thingie) do
     update_counter("metrics_test.\#{thingie}.count", 1)
   end

   def timer_test do
     timed("metrics_test.timer_test.timings") do
       OtherModule.slow_method
     end
   end

   @timed(key: "timed.function")
   def function_that_is_timed do
     OtherModule.slow_method
   end

   @timed(key: :auto) # The key will be "parent_module.metrics_test.another_timed_function"
   def another_timed_function do
     OtherModule.slow_method
   end
 end

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Clears a counter with the given name.

Ensures a metric is correctly registered in Elixometer. This means that Elixometer knows about it and its metrics are subscribed to an exometer reporter

Callback implementation for GenServer.init/1.

Ensures that a metric is subscribed to an exometer reporter.

Updates a timer metric. If the metric doesn't exist, it will be created and subscribed to the default reporter.

Updates a counter metric. If the metric doesn't exist, the metric is created and the metric is subscribed to the default reporter.

Updates a gauge metric. If the metric doesn't exist, the metric is created and the metric is subscribed to the default reporter.

Updates a histogram with a new value. If the metric doesn't exist, a new metric is created and subscribed to.

Updates and alternately creates spiral metric. A spiral metric is a metric maintains a series of internal slots that "age out" and are replaced by newer values. This is useful for maintaining QPS stats.

Link to this section Types

Specs

metric_name() :: String.t() | String.Chars.t()

Link to this section Functions

Link to this function

add_counter(metric_name)

View Source
Link to this function

add_counter(metric_name, ttl_millis)

View Source

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

clear_counter(metric_name)

View Source

Specs

clear_counter(metric_name()) :: :ok | {:error, any()}

Clears a counter with the given name.

Link to this function

ensure_metric_defined(name, defn_fn)

View Source
Link to this function

ensure_registered(metric_name, register_fn)

View Source

Ensures a metric is correctly registered in Elixometer. This means that Elixometer knows about it and its metrics are subscribed to an exometer reporter

Link to this function

get_metric_value(metric_name)

View Source

Specs

get_metric_value(metric_name()) :: {:ok, any()} | {:error, :not_found}
Link to this function

get_metric_value(metric_name, data_point)

View Source

Specs

get_metric_value(metric_name(), :exometer.datapoint()) ::
  {:ok, any()} | {:error, :not_found}
Link to this function

get_metric_values(metric_name)

View Source

Specs

get_metric_values(metric_name()) :: [
  {:exometer.name(), :exometer.type(), :exometer.status()}
]
Link to this function

get_metric_values(metric_name, data_point)

View Source

Specs

get_metric_values(metric_name(), :exometer.datapoint()) ::
  {:ok, integer()} | {:error, :not_found}

Callback implementation for GenServer.init/1.

Link to this function

metric_subscribed?(name)

View Source

Ensures that a metric is subscribed to an exometer reporter.

Link to this macro

timed(name, units \\ :microsecond, list)

View Source (macro)

Updates a timer metric. If the metric doesn't exist, it will be created and subscribed to the default reporter.

The time units default to microseconds, but you can also pass in any of the units in System.time_unit/0, with the exception of pos_integer. This includes :second, :millisecond, :microsecond, and :nanosecond.

Note that nanoseconds are provided for convenience, but Erlang does not actually provide this much granularity.

Link to this function

update_counter(name, delta, list \\ [reset_seconds: nil])

View Source

Specs

update_counter(String.t(), integer(), [{:reset_seconds, nil | integer()}]) ::
  :ok

Updates a counter metric. If the metric doesn't exist, the metric is created and the metric is subscribed to the default reporter.

If the value of the :reset_seconds option is greater than zero, the counter will be reset automatically at the specified interval.

Link to this function

update_gauge(name, value)

View Source

Specs

update_gauge(String.t(), number()) :: :ok

Updates a gauge metric. If the metric doesn't exist, the metric is created and the metric is subscribed to the default reporter.

Link to this function

update_histogram(name, delta, aggregate_seconds \\ 60, truncate \\ true)

View Source

Specs

update_histogram(String.t(), number(), pos_integer(), boolean()) :: :ok

Updates a histogram with a new value. If the metric doesn't exist, a new metric is created and subscribed to.

Link to this function

update_spiral(name, delta, opts \\ [time_span: :timer.seconds(60), slot_period: 1000])

View Source

Specs

update_spiral(String.t(), number(),
  time_span: pos_integer(),
  slot_period: pos_integer()
) :: :ok

Updates and alternately creates spiral metric. A spiral metric is a metric maintains a series of internal slots that "age out" and are replaced by newer values. This is useful for maintaining QPS stats.