Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Statsd# JSON

rsdy edited this page Sep 29, 2018 · 5 revisions

The current protocol used by ingraind is an extension of StatsD semantics, and DataDog's tag system. Specifically, the protocol uses semantic type information for tags and the value, and contains a kind bitfield to encode which aggregation methods make sense for the metric. An example payload looks like so:

[{"timestamp":1532037881452291903,
  "kind":9,
  "name":"volume.in_byte",
  "measurement":8,
  "tags: {
    "proto": "tcp4",
    "task_id": "83721797520628",
    "process": "python",
    "d_ip": "1.2.3.4",
    "s_port": "2672",
    "d_port": "39914",
    "s_ip":"0.0.0.0"
  }
 }
]

The description of fields:

  • timestamp: nanoseconds from the UNIX epoch
  • kind: a bitfield that encodes which StatsD types can be used to aggregate data. For values, see below.
  • name: the name of the metric, plus type information. Currently _byte and _count types refer to bytes and number of events, respectively.
  • measurement: the numeric value for the metric
  • tags: a list of tags that can be used to provide additional context about a metric.

The key for tags also encodes type information in the _type suffix. The keys and type annotations are more or less free form, and instead of machine types, refer to semantic types. Ie. an IP4 address is _ip instead of u32, a port number is _port instead of u16, and so on.

It is expected that the backend contains logic to handle some of the type annotations in its aggregation logic, and is be able to handle new additions gracefully.

The kind bitfield is defined like so, with values corresponding to their StatsD definition. It is a bitfield because one metric could be aggregated in different ways, but not all of those might make sense. The defined kinds closely follow the [StatsD definitions](](https://docs.datadoghq.com/developers/dogstatsd/data_types/):

pub mod kind {
    pub type Kind = u16;
    pub const COUNTER: Kind = 1;
    pub const GAUGE: Kind = 2;
    pub const METER: Kind = 4;
    pub const HISTOGRAM: Kind = 8;
}
Kind Description
COUNTER Counts of events at T
GAUGE Value of metric at T
METER Rate of events at T, d(COUNTER)/dt
HISTOGRAM Derive count, avg, max, 95%