Barograph.Writer (barograph v0.1.0)

Copy Markdown View Source

Owns the single write connection to a Barograph database (spec §7).

All writes funnel through this one process. Incoming samples are buffered and committed in a single transaction when either :batch_size samples are buffered or :batch_timeout milliseconds have elapsed — whichever comes first (spec §7.2). If the buffer grows beyond :max_buffer, writes are rejected with {:error, :overloaded} rather than growing without bound.

Summary

Functions

All registered aggregate definitions.

Returns a specification to start this module under a supervisor.

Creates a continuous aggregate. See Barograph.Aggregate.create/5.

Synchronously commits any buffered samples.

Refreshes every registered aggregate up to now - lag.

Returns the database's time unit (:second, :millisecond, :microsecond).

Buffers a single sample for the next batch commit.

Buffers a list of {metric, labels, value, ts} samples.

Functions

aggregate_definitions(writer)

@spec aggregate_definitions(GenServer.name()) :: [Barograph.Aggregate.definition()]

All registered aggregate definitions.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

create_aggregate(writer, name, opts)

@spec create_aggregate(GenServer.name(), String.t(), keyword()) ::
  :ok | {:error, term()}

Creates a continuous aggregate. See Barograph.Aggregate.create/5.

flush(writer)

@spec flush(GenServer.name()) :: :ok

Synchronously commits any buffered samples.

refresh_aggregates(writer)

@spec refresh_aggregates(GenServer.name()) :: :ok

Refreshes every registered aggregate up to now - lag.

start_link(opts)

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

time_unit(arg)

@spec time_unit(GenServer.name()) :: atom()

Returns the database's time unit (:second, :millisecond, :microsecond).

Read from the Registry, not from the writer process — the unit is immutable per file, and the read path must not couple to writer liveness (e.g. during a long aggregate refresh).

write(writer, metric, labels, value, ts)

@spec write(GenServer.name(), String.t(), map(), number(), integer() | nil) ::
  :ok | {:error, :overloaded}

Buffers a single sample for the next batch commit.

write_many(writer, samples)

@spec write_many(GenServer.name(), [{String.t(), map(), number(), integer() | nil}]) ::
  :ok | {:error, :overloaded}

Buffers a list of {metric, labels, value, ts} samples.