Tinkex.Metrics (Tinkex v0.3.4)

View Source

Lightweight metrics aggregation for Tinkex telemetry events.

The server subscribes to [:tinkex, :http, :request, :stop] and keeps counters for successes/failures plus latency histograms. Public helpers allow recording custom counters, gauges, and histograms for experiment tracking.

Summary

Functions

Block until the server has processed all prior casts.

Increment a counter metric by the provided delta (default: 1).

Record a histogram sample (value in milliseconds).

Reset all metrics state.

Set a gauge to a specific value.

Return a snapshot of counters, gauges, and histograms.

Start the metrics server.

Types

histogram_snapshot()

@type histogram_snapshot() :: %{
  count: non_neg_integer(),
  mean: float() | nil,
  min: float() | nil,
  max: float() | nil,
  p50: float() | nil,
  p95: float() | nil,
  p99: float() | nil
}

metric_name()

@type metric_name() :: atom()

snapshot()

@type snapshot() :: %{
  counters: %{optional(metric_name()) => number()},
  gauges: %{optional(metric_name()) => number()},
  histograms: %{optional(metric_name()) => histogram_snapshot()}
}

Functions

flush()

@spec flush() :: :ok

Block until the server has processed all prior casts.

handle_event(arg1, measurements, metadata, config)

@spec handle_event([atom()], map(), map(), term()) :: :ok

Telemetry handler entrypoint.

increment(name, delta \\ 1)

@spec increment(metric_name(), number()) :: :ok

Increment a counter metric by the provided delta (default: 1).

record_histogram(name, value_ms)

@spec record_histogram(metric_name(), number()) :: :ok

Record a histogram sample (value in milliseconds).

reset()

@spec reset() :: :ok

Reset all metrics state.

set_gauge(name, value)

@spec set_gauge(metric_name(), number()) :: :ok

Set a gauge to a specific value.

snapshot()

@spec snapshot() :: snapshot()

Return a snapshot of counters, gauges, and histograms.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the metrics server.

Options:

  • :enabled - turn metrics on/off (defaults to application env, true)
  • :latency_buckets - histogram buckets in milliseconds