View Source Zexbox.Metrics.Series (Zexbox v1.4.0)

This module defines a simple struct to write metrics to InfluxDB.

the attributes are:

  • measurement - The name of the measurement
  • fields - The fields of the measurement, these are the values you want to aggregate on
  • tags - The tags of the measurement, these are usually identifiers for the values but you can't aggregate on them
  • timestamp - The timestamp of the measurement, it is optional, if it's missing in the struct, InfluxDB will use the current time

Summary

Functions

Adds a field to the series

Creates a new struct with the given measurement and the current time as the timestamp

Adds a tag to the series

Types

t()

@type t() :: %Zexbox.Metrics.Series{
  fields: map(),
  measurement: String.t(),
  tags: map(),
  timestamp: DateTime.t() | nil
}

Functions

field(series, key, value)

@spec field(t(), atom(), any()) :: t()

Adds a field to the series

Examples

iex> Series.field(%Series{measurement: "my_measurement"}, :field1, 42)
%Series{
  measurement: "my_measurement",
  fields: %{field1: 42},
  tags: %{},
  timestamp: ~U[2021-09-29 12:00:00Z]
}

new(measurement)

@spec new(String.t()) :: t()

Creates a new struct with the given measurement and the current time as the timestamp

Examples

iex> Series.new("my_measurement")
%Series{
  measurement: "my_measurement",
  fields: %{},
  tags: %{},
  timestamp: ~U[2021-09-29 12:00:00Z]
}

tag(series, key, value)

@spec tag(t(), atom(), any()) :: t()

Adds a tag to the series

Examples

iex> Series.tag(%Series{measurement: "my_measurement"}, :tag1, "tag_value")
%Series{
  measurement: "my_measurement",
  fields: %{},
  tags: %{tag1: "tag_value"},
  timestamp: ~U[2021-09-29 12:00:00Z]
}