Influx v0.0.1 Influx View Source

InfluxDB driver.

Quick Setup

# In your config/config.exs file
config :my_app, Sample.InfluxDB,
  url: "http://localhost:8086",
  database: "example_db"

# In your application code
defmodule Sample.InfluxDB do
  @moduledoc ~S"My InfluxDB instance."
  use Influx,
    otp_app: :my_app,
    adapter: Influx.Adapters.HTTPX # Optional, HTTPX is default.
end

defmodule Sample.App do
  alias Sample.InfluxDB

  def log do
    InfluxDB.query!("CREATE DATABASE example_db")
    InfluxDB.write!("mymeas,mytag=1 myfield=90 1463683075", precision: :second)
  end
end

Installation

The package can be installed by adding influx to your list of dependencies in mix.exs:

def deps do
  [
    {:influx, "~> 0.0.1"}
  ]
end

Link to this section Summary

Types

Influx request error

Influx host url

Influx profiling

Influx write and query response

Influx write option

Influx write options

Functions

InfluxDB driver

InfluxDB exposes statistics and information about its runtime

Fetch the build and version of an InfluxDB instance

Ping the Influx server to check the connections settings and confirm your InfluxDB instance is up and running

InfluxDB supports the Go net/http/pprof format, which is useful for troubleshooting. The pprof package serves runtime profiling data in the format expected by the pprof visualization tool

Track the number of writes and queries to InfluxDB per username and IP address

Use this to write data to a pre-existing database

Link to this section Types

Link to this type error() View Source
error() :: {:error, atom() | Influx.Error.t()}

Influx request error.

Influx host url.

Link to this type profile() View Source
profile() :: :all | :block | :goroutine | :heap | :mutex | :threadcreate

Influx profiling..

Influx write and query response.

Link to this type write_option() View Source
write_option() ::
  :database
  | :username
  | :password
  | :precision
  | :consistency
  | :retention_policy

Influx write option.

Link to this type write_options() View Source
write_options() :: [{write_option(), term()}]

Influx write options.

Link to this section Functions

Link to this macro __using__(opts \\ []) View Source (macro)

InfluxDB driver.

Quick Setup

# In your config/config.exs file
config :my_app, Sample.InfluxDB,
  url: "http://localhost:8086",
  database: "example_db"

# In your application code
defmodule Sample.InfluxDB do
  @moduledoc ~S"My InfluxDB instance."
  use Influx,
    otp_app: :my_app,
    adapter: Influx.Adapters.HTTPX # Optional, HTTPX is default.
end

defmodule Sample.App do
  alias Sample.InfluxDB

  def log do
    InfluxDB.query!("CREATE DATABASE example_db")
    InfluxDB.write!("mymeas,mytag=1 myfield=90 1463683075", precision: :second)
  end
end

Installation

The package can be installed by adding influx to your list of dependencies in mix.exs:

def deps do
  [
    {:influx, "~> 0.0.1"}
  ]
end
Link to this function debug!(adapter, host, getter \\ []) View Source
debug!(module(), host(), atom() | [atom()]) :: map() | no_return()

See debug/3.

Link to this function debug(adapter, host, getter \\ []) View Source
debug(module(), host(), atom() | [atom()]) :: {:ok, map()} | Influx.error()

InfluxDB exposes statistics and information about its runtime.

Optionally pass a specific field as atom or for nested values a list of atoms.

Note: The InfluxDB input plugin is available to collect metrics (using the /debug/vars endpoint) from specified Kapacitor instances.

For a list of the measurements and fields, see the InfluxDB input plugin README.

Examples

Getting all debug information

iex> debug()
{:ok, %{cmdline: ["influxd"], ...}}

Getting specific debug information

iex> debug(:cmdline)
{:ok, ["influxd"]}

Getting nested debug information

iex> debug([:memstats, :Alloc])
{:ok, 38566248}

See info/2.

Link to this function info(adapter, host) View Source
info(module(), host()) :: {:ok, Influx.Info.t()} | Influx.error()

Fetch the build and version of an InfluxDB instance.

The build can either be the :open_source or :enterprise version.

Examples

iex> info()
{:ok, %Influx.Info{build: :open_source, version: #Version<1.6.3>}}
Link to this function ping!(adapter, host) View Source
ping!(module(), host()) :: :ok | no_return()

See ping/2.

Link to this function ping(adapter, host) View Source
ping(module(), host()) :: :ok | Influx.error()

Ping the Influx server to check the connections settings and confirm your InfluxDB instance is up and running.

Examples

iex> ping()
:ok
Link to this function profile!(adapter, host, profile \\ :all) View Source
profile!(module(), host(), Influx.profile()) :: map() | no_return()

See profile/3.

Link to this function profile(adapter, host, profile \\ :all) View Source
profile(module(), host(), Influx.profile()) :: {:ok, map()} | Influx.error()

InfluxDB supports the Go net/http/pprof format, which is useful for troubleshooting. The pprof package serves runtime profiling data in the format expected by the pprof visualization tool.

Profiles

It is possible to pass a profile for debugging. Default is :all.

ProfileDescription
:allAll stack traces.
:blockStack traces that led to blocking on synchronization primitives.
:goroutineStack traces of all current goroutines.
:heapSampling of stack traces for heap allocations.
:mutexStack traces of holders of contended mutexes.
:threadcreateStack traces that led to the creation of new OS threads.
Link to this function query!(adapter, host, query, opts \\ []) View Source
query!(
  module(),
  URI.t() | String.t(),
  String.t(),
  Influx.Config.write_options()
) :: :ok | no_return()

See query/4.

Link to this function query(adapter, host, query, opts) View Source
query(module(), URI.t() | String.t(), String.t(), Influx.Config.write_options()) ::
  {:ok, [map()]} | Influx.error()
Link to this function requests!(adapter, host, duration \\ 10) View Source
requests!(module(), host(), pos_integer()) :: map() | no_return()

See requests/3.

Link to this function requests(adapter, host, duration \\ 10) View Source
requests(module(), host(), pos_integer()) :: {:ok, map()} | Influx.error()

Track the number of writes and queries to InfluxDB per username and IP address.

Optionally pass the amount of seconds to track writes and queries. (Defaults to 10s.)

Examples

Track requests over a ten-second interval

iex> requests()
{:ok, %{"user1:123.45.678.91" => %{writes: 1, queries: 0}}}

The response shows that, over the past ten seconds, the user1 user sent one request to the write and no requests to query from the 123.45.678.91 IP address.

Track requests over a one-minute interval

iex> requests(60)
{:ok, %{
  "user1:123.45.678.91" => %{writes: 3, queries: 0},
  "user1:000.0.0.0" => %{writes: 0, queries: 16},
  "user2:xx.xx.xxx.xxx" => %{writes: 4, queries: 0}
}}

The response shows that, over the past minute, user1 sent three requests to write from 123.45.678.91, user1 sent 16 requests to query from 000.0.0.0, and user2 sent four requests to write from xx.xx.xxx.xxx.

Link to this function select(adapter, host, fields, opts) View Source
Link to this function write!(adapter, host, write, opts \\ []) View Source
write!(
  module(),
  URI.t() | String.t(),
  String.t(),
  Influx.Config.write_options()
) :: :ok | no_return()

See write/4.

Link to this function write(adapter, host, write, opts \\ []) View Source
write(module(), URI.t() | String.t(), String.t(), Influx.Config.write_options()) ::
  :ok | Influx.error()

Use this to write data to a pre-existing database.

It is recommend to write points in batches of 5,000 to 10,000 points. Smaller batches, and more requests, will result in sub-optimal performance.

Options

Database

(Required)

database: String.t

Sets the target database for the write.

The database can only be set in the configuration.

Username

(Optional, if you haven’t enabled authentication. Required if you’ve enabled authentication.)

username: String.t

Sets the username for authentication if you’ve enabled authentication. The user must have write access to the database. Use with the password: option.

The username can also be passed in the url: config.

Password

(Optional, if you haven’t enabled authentication. Required if you’ve enabled authentication.)

password: String.t

Sets the password for authentication if you’ve enabled authentication. Use with the username: option.

The password can also be passed in the url: config.

Consistency

(Optional, available with InfluxDB Enterprise clusters only.)

consistency: :any | :one | :quorum | :all

Sets the write consistency for the point. InfluxDB assumes that the write consistency is :one if you do not specify consistency:. See the InfluxDB Enterprise documentation for detailed descriptions of each consistency option.

Precision

(Optional)

precision: :nanosecond | :microsecond | :millisecond | :second | :minute | :hour

Sets the precision for the supplied Unix time values. InfluxDB assumes that timestamps are in nanoseconds if you do not specify precision.

We recommend using the least precise precision possible as this can result in significant improvements in compression.

Retention Policy Name

(Optional)

retention_policy: String.t

Sets the target retention policy for the write. InfluxDB writes to the DEFAULT retention policy if you do not specify a retention policy.

Examples

Write a point to the database mydb with a timestamp in seconds

iex> write("mymeas,mytag=1 myfield=90 1463683075", database: "mydb", precision: :second)
:ok

Write a point to the database mydb and the retention policy myrp

iex> write("mymeas,mytag=1 myfield=90", database: "mydb", retention_policy: "myrp")
:ok

Writing to a secured InfluxDB

Correct credentials:

iex> write("mymeas,mytag=1 myfield=91", database: "mydb", username: "myuser", password: "mypassword")
:ok

Invalid credentials:

iex> write("mymeas,mytag=1 myfield=91", database: "mydb", username: "myuser", password: "notmypassword")
{:error, %Influx.Error{message: "authorization failed"}}