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
Returns a specification to start this module under a supervisor.
See Supervisor
.
Specs
clear_counter(metric_name()) :: :ok | {:error, any()}
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
Specs
get_metric_value(metric_name()) :: {:ok, any()} | {:error, :not_found}
Specs
get_metric_value(metric_name(), :exometer.datapoint()) :: {:ok, any()} | {:error, :not_found}
Specs
get_metric_values(metric_name()) :: [ {:exometer.name(), :exometer.type(), :exometer.status()} ]
Specs
get_metric_values(metric_name(), :exometer.datapoint()) :: {:ok, integer()} | {:error, :not_found}
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.
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.
Specs
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.
Specs
Updates a gauge metric. If the metric doesn't exist, the metric is created and the metric is subscribed to the default reporter.
update_histogram(name, delta, aggregate_seconds \\ 60, truncate \\ true)
View SourceSpecs
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.
update_spiral(name, delta, opts \\ [time_span: :timer.seconds(60), slot_period: 1000])
View SourceSpecs
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.