View Source Instream.Connection behaviour (Instream v2.0.0-rc.0)

Defines a connection to an InfluxDB instance.

Connection Definition

defmodule MyConnection do
  use Instream.Connection, otp_app: :my_app
end

This connection will fetch its configuration from the application environment as defined by :otp_app. As an alternative you can define the configuration in the module definition itself:

defmodule MyConnection do
  use Instream.Connection,
    config: [
      version: :v1,
      host: "influxdb.example.com",
      scheme: "http"
    ]
end

Both inline and :otp_app configuration can be mixed. In this case the application configuration will overwrite any inline values.

For more information on how to configure your connection please refer to the documentation of Instream.Connection.Config.

InfluxDB version

By default a connection module will expect to communicate with an InfluxDB 1.x server (version: :v1). Configure version: :v2 if you are running an InfluxDB 2.x server.

Link to this section Summary

Callbacks

Returns a supervisable connection child_spec.

Returns the connection configuration.

Pings the connection server.

Executes a reading query.

Checks the status of the connection server.

Determines the version of the connection server.

Executes a writing query.

Link to this section Types

Specs

e_version_mismatch() :: {:error, :version_mismatch}

Specs

Specs

precision() ::
  :hour
  | :minute
  | :second
  | :millisecond
  | :microsecond
  | :nanosecond
  | :rfc3339

Link to this section Callbacks

Specs

child_spec(_ignored :: term()) :: Supervisor.child_spec()

Returns a supervisable connection child_spec.

Specs

config(key :: atom() | nil) :: Keyword.t() | term()

Returns the connection configuration.

Specs

ping(opts :: Keyword.t()) :: :pong | :error

Pings the connection server.

Specs

query(query :: String.t(), opts :: Keyword.t()) :: any()

Executes a reading query.

Options:

  • database: use a database differing from the connection config for reading
  • method: whether to use a :get or :post request
  • org: use an organization differing from the connection config for reading
  • precision: return data with a "precision" other than :rfc3339

Specs

status(opts :: Keyword.t()) :: :ok | :error | e_version_mismatch()

Checks the status of the connection server.

Only available with InfluxDB v1.x connections.

Specs

version(opts :: Keyword.t()) :: String.t() | :error

Determines the version of the connection server.

If the version if undetectable (no header returned) it will be reported as "unknown". If the host is unreachable or an error occurred the response will be :error.

Specs

write(payload :: map() | [map()], opts :: Keyword.t()) :: any()

Executes a writing query.

Usable options depend on the writer module configured.