InfluxEx.Client (influx_ex v0.3.1)

The primary configuration to talking with InfluxDB

The client allows for customizing how JSON, CSV, and HTTP are all handled. By default the client will try to use :jason for JSON, :nimble_csv for CSV, and :req for HTTP requests.

To ensure all these libraries are available add these lines to your deps in your mix.exs:

{:req, "~> 0.2.0"},
{:jason, "~> 1.0"},
{:nimble_csv, "~> 1.0"}

If you prefer to use other libraries you can customize these options.

The client is not processed based and the consuming application will need provide any process architecture to manage client state.

The reason for this is to allow maximal flexibility around how a consumer will want to call the InfluxEx functions and allow the user to decided if a process is necessary.

json-library

JSON Library

By default Influx.Client will default to using Jason.decode/1 as the decode function. You can pass an InfluxEx.decoder() function to the :json_decoder field when creating a new client.

By default Influx.Client will use the :jason library to handle JSON encoding and decoding. If you want to use a different solution you can provide a module that implements the InfluxEx.JSONLibrary behaviour to the :json_library option to InfluxEx.Client.new/2

InfluxEx.Client.new("mytoken", json_library: MyJSONLib)

csv-library

CSV library

By default Influx.Client will use the :nimble_csv library as the CSV library. If you want to provide your own library you can pass the name name of your module, which implements the InfluxEx.CSVLibrary behaviour to the :csv_library option when calling InfluxEx.Client.new/2.

It's important to keep the CSV headers, so if your custom function tries to skip headers you might have to wrap the function in order to pass options to your decoder to keep the headers.

InfluxEx.Client.new("mytoken", csv_library: MyCSVLibrary)

http-library

HTTP library

InfluxEx provides a behaviour for supporting different HTTP clients. You can wrap your chosen HTTP client in the InfluxEx.HTTP behaviour and configure the client to use your implementation. By default InfluxEx using req.

InfluxEx.Client.new("mytoken", http_client: MyHTTPLibraryImplementation)

Link to this section Summary

Types

t()

Client data structure

Link to this section Types

@type opt() ::
  {:host, :inet.hostname()}
  | {:port, integer()}
  | {:json_library, InfluxEx.JSONLibrary.t()}
  | {:csv_library, InfluxEx.CSVLibrary.t()}
  | {:http_client, InfluxEx.HTTP.t()}
  | {:org, InfluxEx.Org.name()}
  | {:org_id, InfluxEx.Org.id()}
@type t() :: %InfluxEx.Client{
  csv_library: InfluxEx.CSVLibrary.t(),
  host: :inet.hostname(),
  http_client: InfluxEx.HTTP.t(),
  json_library: InfluxEx.JSONLibrary.t(),
  org: InfluxEx.Org.name() | nil,
  org_id: InfluxEx.Org.id() | nil,
  port: integer(),
  token: InfluxEx.token()
}

Client data structure

  • :token - the API token provided by InfluxDB (required)
  • :host - the host name for the InfluxDB server, defaults to localhost
  • :port - the port number for the InfluxDB server, defaults to 8086
  • :json_library - a module that provides functionality for encoding and decoding JSON
  • :csv_library - a module that implements the InfluxEx.CSVLibrary
  • :http_client - a module that implements the InfluxEx.HTTP behaviour, by default this will try to use the InfluxEx.HTTP.Req module.
  • :org - the name of the organization inside of the InfluxDB server.
  • :org_id the org id of the organization inside of the InfluxDB server.

Link to this section Functions

Link to this function

new(token, opts \\ [])

@spec new(InfluxEx.token(), [opt()]) :: t()