pinterest/elixometer

Name: elixometer

Owner: Pinterest

Description: A light Elixir wrapper around exometer.

Created: 2015-08-13 20:39:06.0

Updated: 2018-05-23 20:21:32.0

Pushed: 2018-05-17 23:11:51.0

Homepage:

Size: 120

Language: Elixir

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Elixometer

Build Status Coverage Status

A light wrapper around exometer.

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

Installation

Add the following to your dependencies in mix.exs:

ixometer, "~> 1.2"}

Or to track the master development branch:

ixometer, github: "pinterest/elixometer"}

Then, add :elixometer to your applications. That's it!

Configuration

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

ig(:exometer_core, report: [reporters: [{:exometer_report_tty, []}]])
ig(:elixometer,
porter: :exometer_report_tty,
v: Mix.env,
tric_prefix: "myapp")

Metrics are prepended with the metric_prefix, the type of metric and the environment name.

The optional update_frequency key of the :elixometer config controls the interval between reports. By default this is set to 1000 ms in the dev environment and 20 ms in the test environment.

You can use an environment variable to set the env.

ig :elixometer, env: {:system, "ELIXOMETER_ENV"}

By default, metrics are formatted using Elixometer.Utils.name_to_exometer/2. This function takes care of composing metric names with prefix, environment and the metric type (e.g. myapp_prefix.dev.timers.request_time).

This behaviour can be overridden with a custom formatter function, by adding the following configuration entry:

ig :elixometer, Elixometer.Updater,
rmatter: &MyApp.Metrics.my_custom_formatter/2

Elixometer uses pobox to prevent overload. A maximum size of message buffer, defaulting to 1000, can be configured with:

ig :elixometer, Elixometer.Updater,
x_messages: 5000
Excluding datapoints subscriptions

By default, adding a histogram adds for example 11 subscriptions ([:n, :mean, :min, :max, :median, 50, 75, 90, 95, 99, 999]). If you would like to restrict which of these you care about, you can exclude some like so:

ig :elixometer, excluded_datapoints: [:median, 999]
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 terms, a metric is named with a period separated bitstring. Presently, Elixometer supports timers, histograms, gauges, counters, and spirals.

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:

odule ParentModule.MetricsTest do
e Elixometer

Updating a counter
f counter_test(thingie) do
update_counter("metrics_test.\#{thingie}.count", 1)
d

Updating a spiral
f spiral_test(thingie) do
update_spiral("metrics_test.\#{thingie}.qps", 1)
d

Timing a block of code in a function
f timer_test do
timed("metrics_test.timer_test.timings") do
  OtherModule.slow_method
end
d

Timing a function. The metric name will be [:timed, :function]
imed(key: "timed.function") # key will be: prefix.dev.timers.timed.function
f function_that_is_timed do
OtherModule.slow_method
d

Timing a function with an auto generated key
The key will be "<prefix>.<env>.timers.parent_module.metrics_test.another_timed_function"
If the env is prod, the environment is omitted from the key
imed(key: :auto)
f another_timed_function do
OtherModule.slow_method
d

Additional Reporters

By default, Elixometer only requires the exometer_core package. However, some reporters (namely OpenTSDB and Statsd) are only available by installing the full exometer package. If you need the full package, all you need to do is update your mix.exs to include exometer as a dependency and start it as an application. For example:

application do

applications: [:exometer,
... other applications go here
],
...



 deps do
:exometer_core, github: "PSPDFKit-labs/exometer_core"}]

In case a reporter allows for extra configuration options on subscribe, you can configure them in your elixometer config like so:

ig(:elixometer,
.
bscribe_options: [{:tag, :value1}])

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.