View Source Zexbox.Metrics.Client (Zexbox v0.5.0)

A client module for writing metrics to InfluxDB.

Overview

This module provides functions to write metrics to InfluxDB, a time-series database that allows for efficient storage and querying of data with a timestamp.

To use this module, you need to have the Zexbox.Metrics.Connection application running. Make sure to start it as an application in your supervision tree:

def start(_type, _args) do
  children = [
    {Zexbox.Metrics.Connection, []}
  ]
  Supervisor.start_link(children, strategy: :one_for_one)
end

Writing Metrics

The main function provided by this module is write_metric/1. It accepts a metric data structure and writes it to InfluxDB.

Examples

Writing Custom metrics

  iex> metric = %Zexbox.Metrics.Series.Generic{
  ...>   measurement: "my_measurement",
  ...>   fields: %{
  ...>     "my_field" => 1
  ...>   },
  ...>   tags: %{
  ...>     "my_tag" => "my_value"
  ...>   }
  ...> }
  iex> Zexbox.Metrics.Client.write_metric(metric)
  {:ok, %Zexbox.Metrics.Series.Generic{
    measurement: "my_measurement",
    fields: %{
      "my_field" => 1
    },
    tags: %{
      "my_tag" => "my_value"
    }
  }}

### Error Handling If there is an error while writing the metric, the function will log the error using the Logger module. without crashing the process

Summary

Functions

Write a metric to InfluxDB.

Types

@type series() :: %Zexbox.Metrics.ControllerSeries{
  fields: term(),
  tags: term(),
  timestamp: term()
}

Functions

@spec write_metric(series()) :: tuple()

Write a metric to InfluxDB.

Examples:

iex> Zexbox.Metrics.Client.write_metric(%ControllerSeries{})
{:ok, %ControllerSeries{}}