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
@spec write( InfluxElixir.Client.connection() | atom(), iodata() | InfluxElixir.Write.Point.t() | [InfluxElixir.Write.Point.t()], keyword() ) :: InfluxElixir.Client.write_result()
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 withInfluxElixir.Connection(a name that is not registered is{:error, {:invalid_connection, name}})payload- encoded line protocol (a binary or iodata), aInfluxElixir.Write.Pointor a list of them. Points are encoded withInfluxElixir.Write.LineProtocol.encode/2for the call's:precisionand the connection'sapi_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-truecompresses the payload whatever its size,falsenever does; by default only payloads over 1024 bytes are. An explicittrueused 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}