# `Zexbox.Metrics.Series`
[🔗](https://github.com/Intellection/zexbox/blob/main/lib/zexbox/metrics/models/series.ex#L1)

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

# `t`

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

# `field`

```elixir
@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`

```elixir
@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`

```elixir
@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]
    }

---

*Consult [api-reference.md](api-reference.md) for complete listing*
