• Stars
    star
    827
  • Rank 53,018 (Top 2 %)
  • Language
    Elixir
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A light Elixir wrapper around exometer.

Elixometer

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:

{:elixometer, "~> 1.5"}

Or to track the master development branch:

{:elixometer, 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:

config(:exometer_core, report: [reporters: [{:exometer_report_tty, []}]])
config(:elixometer,
  reporter: :exometer_report_tty,
  env: Mix.env,
  metric_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.

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

Some reporters know how to handle multiple metrics reported at the same time. Or perhaps you want to write a custom reporter, and would like to receive all data points for a single metric all at once. This can be achieved by adding the report_bulk: true option to the reporter configuration, and adding bulk_subscribe: true to the elixometer configuration. Like so:

config :exometer_core,
  report: [
    reporters: [
      {My.Custom.Reporter, [report_bulk: true]}
    ]
  ]

config :elixometer,
  # ...
  bulk_subscribe: true

By default, metrics are formatted using Elixometer.Utils.format/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 module (implementing the Elixometer.Formatter behaviour) by adding the following configuration entry:

config :elixometer, Elixometer.Updater,
  formatter: MyApp.Formatter

A formatting module implements the Elixometer.Formatter behaviour and implements a single function, format as such:

defmodule MyApp.Formatter do
  @behaviour Elixometer.Formatter

  # If you prefer to hyphen-separate your strings, perhaps
  def format(metric_type, name) do
    String.split("#{metric_type}-#{name}", "-")
  end
end

A formatting function can also be used as the configuration entry, provided it follows the same signature as a formatting module:

config :elixometer, Elixometer.Updater,
  formatter: &MyApp.Formatter.format/2

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

config :elixometer, Elixometer.Updater,
  max_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:

config :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:

defmodule ParentModule.MetricsTest do
  use Elixometer

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

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

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

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

  # 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
  @timed(key: :auto)
  def another_timed_function do
    OtherModule.slow_method
  end
end

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:

def application do
  [
    applications: [:exometer,
    ... other applications go here
    ],
    ...
  ]
end

defp deps do
  [{:exometer_core, github: "Feuerlabs/exometer_core"}]
end

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

config(:elixometer,
  ...
  subscribe_options: [{:tag, :value1}])

Custom Reporters

The documentation on custom reporters in exometer is fairly difficult to find, and isn't exactly correct. It is still quite useful though, and can be found here.

Your best bet is to define a module that uses the :exometer_report behaviour, and use @impl on the functions that you add to conform to that behaviour. That will make sure that each function aligns with the behaviour, and that you haven't missed any required ones.

There is one function that is not included as part of the erlang behaviour, but that you may want, which is exometer_report_bulk/3. If and only if you have defined that function in your reporter and you passed report_bulk: true as an option to the reporter, it will pass a list of datapoint/value pairs to your exometer_report_bulk/3.

More Repositories

1

ktlint

An anti-bikeshedding Kotlin linter with built-in formatter
Kotlin
6,006
star
2

gestalt

A set of React UI components that supports Pinterestโ€™s design language
JavaScript
4,205
star
3

PINRemoteImage

A thread safe, performant, feature rich image fetcher
C
3,998
star
4

PINCache

Fast, non-deadlocking parallel object cache for iOS, tvOS and OS X
Objective-C
2,644
star
5

secor

Secor is a service implementing Kafka log persistence
Java
1,832
star
6

teletraan

Teletraan is Pinterest's deploy system.
Java
1,792
star
7

querybook

Querybook is a Big Data Querying UI, combining collocated table metadata and a simple notebook interface.
TypeScript
1,728
star
8

knox

Knox is a secret management service
Go
1,216
star
9

pinball

Pinball is a scalable workflow manager
JavaScript
1,047
star
10

mysql_utils

Pinterest MySQL Management Tools
Python
878
star
11

snappass

Share passwords securely
Python
812
star
12

pymemcache

A comprehensive, fast, pure-Python memcached client.
Python
740
star
13

bonsai

Understand the tree of dependencies inside your webpack bundles, and trim away the excess.
JavaScript
739
star
14

esprint

Fast eslint runner
JavaScript
657
star
15

bender

An easy-to-use library for creating load testing applications
Go
654
star
16

rocksplicator

RocksDB Replication
C++
640
star
17

DoctorK

DoctorK is a service for Kafka cluster auto healing and workload balancing
Java
633
star
18

plank

A tool for generating immutable model objects
Swift
469
star
19

riffed

Provides idiomatic Elixir bindings for Apache Thrift
Elixir
307
star
20

thrift-tools

thrift-tools is a library and a set of tools to introspect Apache Thrift traffic.
Python
229
star
21

elixir-thrift

A Pure Elixir Thrift Implementation
Elixir
212
star
22

widgets

JavaScript widgets, including the Pin It button.
JavaScript
195
star
23

terrapin

Serving system for batch generated data sets
Java
176
star
24

singer

A high-performance, reliable and extensible logging agent for uploading data to Kafka, Pulsar, etc.
Java
173
star
25

git-stacktrace

Easily figure out which git commit caused a given stacktrace
Python
157
star
26

jbender

An easy-to-use library for creating load testing applications.
Java
155
star
27

ptracer

A library for ptrace-based tracing of Python programs
Python
154
star
28

react-pinterest

JavaScript
153
star
29

pinlater

PinLater is a Thrift service to manage scheduling and execution of asynchronous jobs.
Java
135
star
30

it-cpe-cookbooks

A suite of Chef cookbooks that we use to manage our fleet of client devices
Ruby
117
star
31

memq

MemQ is an efficient, scalable cloud native PubSub system
Java
111
star
32

psc

PubSubClient (PSC)
Java
110
star
33

pinterest-api-demo

JavaScript
105
star
34

PINOperation

Objective-C
102
star
35

api-quickstart

Code that makes it easy to get started with the Pinterest API.
Python
100
star
36

soundwave

A searchable EC2 Inventory store
Java
97
star
37

orion

Management and automation platform for Stateful Distributed Systems
Java
94
star
38

PINFuture

An Objective-C future implementation that aims to provide maximal type safety
Objective-C
81
star
39

kingpin

KingPin is the toolset used at Pinterest for service discovery and application configuration.
Python
69
star
40

arcanist-linters

A collection of custom Arcanist linters
PHP
61
star
41

pagerduty-monit

Wrapper scripts to integrate monit and PagerDuty.
Shell
60
star
42

pinrepo

Pinrepo is a highly scalable solution for storing and serving build artifacts such as debian packages, maven jars and pypi packages.
Python
57
star
43

quasar-thrift

A Thrift server that uses Quasar's lightweight threads to handle connections.
Java
47
star
44

yuvi

Yuvi is an in-memory storage engine for recent time series metrics data.
Java
45
star
45

transformer_user_action

Transformer-based Realtime User Action Model for Recommendation at Pinterest
Python
44
star
46

pinterest-python-sdk

An SDK that makes it quick and easy to build applications with Pinterest API.
Python
35
star
47

slackminion

A python bot framework for slack
Python
22
star
48

atg-research

Python
20
star
49

l10nmessages

L10nMessages is a library that makes internationalization (i18n) and localization (l10n) of Java applications easy and safe.
Java
17
star
50

arcanist-owners

An Arcanist extension for displaying file ownership information
PHP
16
star
51

api-description

OpenAPI descriptions for Pinterest's REST API
15
star
52

thriftcheck

A linter for Thrift IDL files
Go
13
star
53

.github

Pinterest's Open Source Project Template
11
star
54

pinterest-python-generated-api-client

This is the auto-generated code using OpenAPI generator. Generated code comprises HTTP requests to various v5 API endpoints.
Python
10
star
55

homebrew-tap

macOS Homebrew formulas to install Pinterest open source software
Ruby
9
star
56

wheeljack

Work with interdependent python repositories seemlessly.
Python
8
star
57

vscode-gestalt

Visual Studio Code extension for Gestalt, Pinterest's design system
TypeScript
7
star
58

ffffound

FFFFOUND Import tool for Pinterest
HTML
6
star
59

vscode-package-watcher

Watch package lock files and suggest to re-run npm or yarn.
TypeScript
5
star
60

graphql-lint-rules

Pinterest GraphQL Lint Rules
TypeScript
5
star
61

ss-gtm-template

This is a repository to implement the Google Tag Manager server-side tag template for Pinterest API for Conversions to be deployed into Google Community Template Gallery.
Smarty
4
star
62

pinterest-magento2-extension

PHP
3
star
63

Pinterest-Salesforce-Commerce-Cartridge

JavaScript
2
star
64

slate

Resource Lifecycle Management framework
Java
1
star