# `Visualize.Feed.Telemetry`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/feed/telemetry.ex#L1)

An in-process `:telemetry` provider: a collector over `Telemetry.Metrics` definitions,
one push feed per metric (spec/08 §11.6, D-140).

`start_link(metrics: definitions)` attaches one handler for the definitions' events and
collects. A definition is read by its fields — `name`, `event_name`, `measurement`,
`tags`, `tag_values`, `keep`, `unit`, `description`, `reporter_options` — and its
struct's name, so this library takes no dependency on `telemetry_metrics`.
`:telemetry` itself is optional: without it the module compiles and the provider is
never started.

Each metric is a feed (`feeds/1`, `feed/2`) whose rows are `%{t: DateTime, value: v}`
plus the metric's tags, and whose schema says so: `t` the window field, a `:time` field
of `DateTime`s; `value` labeled with the definition's description (else its name), in
the definition's unit as a UCUM
code (`Visualize.Unit.from_telemetry/1`) with the quantity it implies, each tag a
category. A counter's value is the count so far for its tags and a sum's the running
total; a last value's, a summary's and a distribution's the measurement.

`value` says how it was measured (D-160): its `metric_kind` is `:counter` for a counter
or a sum and `:gauge` for every other kind. The definition's
`reporter_options[:visualize]` adds what only the application knows of it — exactly
`polarity`, `bounds`, `target` and `metric_kind`, the last overriding the inference:

    summary("http.request.duration",
      unit: {:native, :millisecond},
      reporter_options: [visualize: [polarity: :lower_is_better, bounds: [0, nil], target: 250]]
    )

The schema checks them, and any other key is refused: an invalid fact stops `start_link/1`
with `{:telemetry_facts, metric, errors}`, the metric named as `feeds/1` keys it.

The collector stamps every row on receipt with its own clock, strictly increasing, and
keeps the newest `keep:` rows of each metric. It honors a window of `DateTime` bounds
and pushes: every `every:` milliseconds each subscriber gets the rows new since the last
flush, its schema sent first at subscription.

# `t`

```elixir
@type t() :: %Visualize.Feed.Telemetry{metric: String.t(), server: GenServer.server()}
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `feed`

```elixir
@spec feed(GenServer.server(), String.t()) :: t()
```

One metric's feed, by its dotted name. A name the collector lacks answers `{:error, {:unknown_metric, name}}`.

# `feeds`

```elixir
@spec feeds(GenServer.server()) :: %{required(String.t()) =&gt; t()}
```

Each metric's feed, by its dotted name (`"vm.memory.total"`).

# `flush`

```elixir
@spec flush(GenServer.server()) :: :ok
```

Every subscriber sent the rows new since the last flush, now.

# `start_link`

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

The collector over `metrics:`, a list of `Telemetry.Metrics` definitions, attached.
Options: `name:`, `keep:` (rows kept per metric, `10_000`), `every:` (the push interval
in milliseconds, `1000`; `nil` pushes only on `flush/1`) and `clock:` (a function of no
argument answering microseconds, `System.os_time(:microsecond)` by default).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
