• Stars
    star
    827
  • Rank 55,139 (Top 2 %)
  • Language
    Elixir
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated over 1 year 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,192
star
2

gestalt

A set of React UI components that supports Pinterest’s design language
TypeScript
4,240
star
3

PINRemoteImage

A thread safe, performant, feature rich image fetcher
Objective-C
4,009
star
4

PINCache

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

querybook

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

secor

Secor is a service implementing Kafka log persistence
Java
1,845
star
7

teletraan

Teletraan is Pinterest's deploy system.
Java
1,807
star
8

knox

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

pinball

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

mysql_utils

Pinterest MySQL Management Tools
Python
883
star
11

snappass

Share passwords securely
Python
837
star
12

pymemcache

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

bonsai

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

rocksplicator

RocksDB Replication
C++
662
star
15

esprint

Fast eslint runner
JavaScript
661
star
16

bender

An easy-to-use library for creating load testing applications
Go
658
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
233
star
21

elixir-thrift

A Pure Elixir Thrift Implementation
Elixir
214
star
22

widgets

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

singer

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

terrapin

Serving system for batch generated data sets
Java
176
star
25

git-stacktrace

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

jbender

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

ptracer

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

react-pinterest

JavaScript
151
star
29

pinlater

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

memq

MemQ is an efficient, scalable cloud native PubSub system
Java
129
star
31

api-quickstart

Code that makes it easy to get started with the Pinterest API.
Python
122
star
32

it-cpe-cookbooks

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

psc

PubSubClient (PSC)
Java
117
star
34

pinterest-api-demo

JavaScript
106
star
35

PINOperation

Objective-C
104
star
36

orion

Management and automation platform for Stateful Distributed Systems
Java
101
star
37

soundwave

A searchable EC2 Inventory store
Java
96
star
38

PINFuture

An Objective-C future implementation that aims to provide maximal type safety
Objective-C
83
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
63
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
58
star
43

transformer_user_action

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

quasar-thrift

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

pinterest-python-sdk

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

yuvi

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

atg-research

Python
41
star
48

slackminion

A python bot framework for slack
Python
22
star
49

api-description

OpenAPI descriptions for Pinterest's REST API
18
star
50

l10nmessages

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

thriftcheck

A linter for Thrift IDL files
Go
16
star
52

arcanist-owners

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

tiered-storage

Pinterest's simplified and efficient Tiered Storage implementation for Kafka
Java
13
star
54

.github

Pinterest's Open Source Project Template
12
star
55

homebrew-tap

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

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
12
star
57

vscode-gestalt

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

wheeljack

Work with interdependent python repositories seemlessly.
Python
8
star
59

ffffound

FFFFOUND Import tool for Pinterest
HTML
8
star
60

vscode-package-watcher

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

graphql-lint-rules

Pinterest GraphQL Lint Rules
TypeScript
6
star
62

ss-gtm-template

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

pinterest-magento2-extension

PHP
4
star
64

Pinterest-Salesforce-Commerce-Cartridge

JavaScript
4
star
65

figma-calculations

TypeScript
2
star
66

slate

Resource Lifecycle Management framework
Java
1
star