dogstat v0.1.0 DogStat

This module provides helper functions to persist meaningful metrics to StatsD or DogstatsD servers.

Code is based on Statix library.

Summary

Functions

Changes DogStat configuration at run-time. Accepts opts is identical to a start_link/1

Decrements the StatsD counter identified by key by the given value

Writes to the StatsD gauge identified by key

Writes value to the histogram identified by key

Increments the StatsD counter identified by key by the given value

Measures the execution time of the given function and writes that to the StatsD timing identified by key

Writes the given value to the StatsD set identified by key

Starts a metric collector process

Writes the given value to the StatsD timing identified by key

Types

key()
key() :: iodata
on_send()
on_send() :: :ok | {:error, term}
options()
options() :: [sample_rate: float, tags: [String.t]]

Functions

configure(opts)

Changes DogStat configuration at run-time. Accepts opts is identical to a start_link/1.

decrement(key, val \\ 1, options \\ [])
decrement(key, value :: number, options) :: on_send

Decrements the StatsD counter identified by key by the given value.

Works same as c:increment/3 but subtracts value instead of adding it. For this reason value should be zero or negative.

Examples

iex> decrement("open_connections", 1, [])
:ok
gauge(key, val, options \\ [])
gauge(key, value :: String.Chars.t, options) :: on_send

Writes to the StatsD gauge identified by key.

Examples

iex> gauge("cpu_usage", 0.83, [])
:ok
histogram(key, val, options \\ [])
histogram(key, value :: String.Chars.t, options) :: on_send

Writes value to the histogram identified by key.

Not all StatsD-compatible servers support histograms. An example of a such server statsite.

Examples

iex> histogram("online_users", 123, [])
:ok
increment(key, val \\ 1, options \\ [])
increment(key, value :: number, options) :: on_send

Increments the StatsD counter identified by key by the given value.

value is supposed to be zero or positive and c:decrement/3 should be used for negative values.

Examples

iex> increment("hits", 1, [])
:ok
measure(key, options \\ [], fun)
measure(key, options, function :: (() -> result)) :: result when result: var

Measures the execution time of the given function and writes that to the StatsD timing identified by key.

This function returns the value returned by function, making it suitable for easily wrapping existing code.

Examples

iex> measure("integer_to_string", [], fn -> Integer.to_string(123) end)
"123"
set(key, val, options \\ [])
set(key, value :: String.Chars.t, options) :: on_send

Writes the given value to the StatsD set identified by key.

Examples

iex> set("unique_visitors", "user1", [])
:ok
start_link(opts)

Starts a metric collector process.

opts accepts connection arguments:

  • enabled? - enables or disables metrics reporting;
  • host - StatsD server host;
  • port - StatsD server port;
  • namespace - will be used as prefix to collected metrics;
  • send_tags? - allows to disable tags for StatsD servers that don’t support them;
  • sink - if set to list, all metrics will be stored in a process state, useful for testing;
timing(key, val, options \\ [])
timing(key, value :: String.Chars.t, options) :: on_send

Writes the given value to the StatsD timing identified by key.

value is expected in milliseconds.

Examples

iex> timing("rendering", 12, [])
:ok