InfluxElixir.Write.Writer (InfluxElixir v0.1.37)

Copy Markdown View Source

Direct single-request write to InfluxDB.

Accepts pre-encoded line protocol binary and forwards it to the configured client implementation. Automatically applies gzip compression for payloads larger than 1 KB, and wraps every write in an [:influx_elixir, :write, ...] telemetry span (see InfluxElixir.Telemetry).

Summary

Functions

Writes line protocol binary to InfluxDB via the configured client.

Functions

write(connection, line_protocol, opts \\ [])

Writes line protocol binary to InfluxDB via the configured client.

Gzips payloads larger than 1024 bytes, and passes gzip: true to the client exactly when it has compressed the payload, so the HTTP client's Content-Encoding: gzip header always matches the body.

Parameters

  • connection - connection term (opaque, passed to client)
  • line_protocol - encoded line protocol binary
  • opts - keyword options forwarded to the client, plus:
    • :client - client module to use instead of the configured one (InfluxElixir.Client.impl/0). Not forwarded to the client.
    • :gzip - true compresses the payload whatever its size, false never does; by default only payloads over 1024 bytes are. An explicit true used to reach the client with the payload uncompressed, and the server refused the header (error decoding gzip stream, verified).

Returns

  • {:ok, :written} on success
  • {:error, reason} on failure

Examples

iex> {:ok, conn} = InfluxElixir.Client.Local.start(database: "mydb")
iex> InfluxElixir.Write.Writer.write(conn, "cpu value=1.0")
{:ok, :written}