InfluxElixir.Write.Writer (InfluxElixir v0.1.53)

Copy Markdown View Source

Direct single-request write to InfluxDB.

Accepts line protocol (a binary or iodata) or InfluxElixir.Write.Points and forwards them 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, or Points, to InfluxDB via the configured client.

Functions

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

Writes line protocol, or Points, 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), or the name of a connection registered with InfluxElixir.Connection (a name that is not registered is {:error, {:invalid_connection, name}})
  • payload - encoded line protocol (a binary or iodata), a InfluxElixir.Write.Point or a list of them. Points are encoded with InfluxElixir.Write.LineProtocol.encode/2 for the call's :precision and the connection's api_version; a point that cannot be encoded is that function's {:error, reason}, and nothing is sent.
  • 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}