AlgoViz

Datadog

medium 27 min

Datadog is a hosted monitoring platform.

Video lesson · Chapter 1 of 5

Trace a checkout measurement before trusting its alert

0:00 / 4:50

Datadog in 90 seconds

1:30Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

Datadog is a service, not a program you install. You install only the Agent, which is open source. It collects numbers from the machine, receives metrics and traces from your applications, reads log files, and sends all of it over HTTPS to Datadog. Storage, dashboards and alerts run at Datadog and are used in a browser.

Everything carries tags such as env:prod and service:cart. Tags connect the parts: from a slow line on a chart you go to the traces of the same service, and from a trace to its logs.

It grew from machine metrics into a broad platform with many separately billed products. This page treats the three that a system design needs, metrics, traces and logs, plus monitors, and leaves the rest out.

Why it exists

Running your own monitoring means a metrics store, a log store, a trace store, dashboards and alerts, with upgrades and people on call for them. A small team may prefer to pay somebody else. It also wants the monitoring to be up when its own data centre is not.

The price is money that grows with your system, data that leaves your network, and dependence on one company. Those three points are the whole decision, so this page spends much of its time on them.

A short history

  1. 2010

    Olivier Pomel and Alexis Le-Quoc found the company in New York.

  2. 2015 and later

    Purchases extend the platform, among them Mortar Data in 2015 and a log service, Logmatic, in 2017.

  3. September 2019

    The company goes public on Nasdaq. In the same month its engineers publish DDSketch, a structure for percentiles that can be merged.

  4. May 2022

    It describes Husky, its third-generation event store on object storage.

  5. March 2023

    An outage hits several regions at once; the company publishes a report.

Words to know

Agent
The program on your hosts that collects and forwards.
Check or integration
A piece of the Agent that reads one kind of system, such as a database.
DogStatsD
The part of the Agent that receives metrics from your code over UDP or a Unix socket.
Tag
A key and value on data, like a label.
Custom metric
A metric of yours; counted as one unique combination of name and tag values.
Distribution
A metric type whose percentiles are computed over all hosts together.
Ingest and index
Receiving data, and keeping it searchable. Two steps, limited and billed separately.
Monitor
A query with thresholds and a message: an alert rule.
Site
One separate copy of the service, for example US1 or EU1. Data is not shared between sites.

How it works

Step through the idea, or press Play.

Step 1 of 3

Collect. The Agent reads the host and receives data from your code

Understand it

Start here

The caretaker service

Imagine you own three houses and hire a caretaker company. It places one small helper in each house, and one office watches all of them.

A helper in every house
123OFFICEhouse 1 ?house 2 ?house 3 ?Three houses, nobody watching

You pay for a helper in every house and for every label that the office keeps.

The idea

Your side and their side

Two owners, one boundary

Inside our system, one host runs our app and the Datadog Agent. The app sends to the Agent over UDP 8125 and TCP 8126. The Agent sends out over HTTPS to Datadog, a box outside our system, on one site such as EU1. People on call get charts and alerts from there.
Everything right of the dashed line belongs to another company. All connections start on your side.
  • Infrastructure

    CPU, memory, disks, containers, cloud services. More than 1,000 integrations.

  • Custom metrics

    Numbers from your own code.

  • Traces (APM)

    The path and time of requests through services.

  • Logs

    Received, processed, then indexed, archived or turned into metrics.

  • Monitors

    Thresholds, change, anomalies, missing data.

  • Dashboards

    All of the above on one page.

The three kinds of signals are introduced in monitoring basics and distributed logging. How one might design such a platform is the exercise metrics monitoring system.

Your side

Inside the Agent

What the Agent does on one host

Ports on the host

PortUseOpen to
8125 UDPDogStatsD metrics from your codeThis host or node only
8126 TCPTracesThis host or node only
5000, 5001The Agent's own state and commandsThis host only
443 outMost data to DatadogThe outside, only outwards
Version 7 is the current major version. The Agent is under the Apache 2.0 licence.
YAML
# /etc/datadog-agent/datadog.yamlapi_key: ENC[datadog_api_key]      # from a secrets backend, not in plain textsite: datadoghq.eu                 # wrong site means no dataenv: prodtags:  - team:shoplogs_enabled: true                 # log collection is off by defaultapm_config:  enabled: true# keep metrics on disk when the network is downforwarder_storage_max_size_in_bytes: 2147483648
Without the last line only memory is used, and the oldest metrics are dropped when it is full.

How long does the buffer last?

2 GiB20 kB/s=2,147,483,64820,000≈107,000 s≈30 hours\frac{2\ \text{GiB}}{20\ \text{kB/s}} = \frac{2{,}147{,}483{,}648}{20{,}000} \approx 107{,}000\,\text{s} \approx 30\ \text{hours}
Assumed: 20 kB of compressed metrics per second from one host. So 2 GiB covers a long weekend night, and the decision is cheap. Logs follow their own path.

In Kubernetes

Inside our cluster the Kubernetes API server gives cluster data to one Cluster Agent. The Cluster Agent passes metadata to two separate nodes, each with its own Agent. Both nodes send HTTPS to Datadog outside the cluster.
One Agent per node as a DaemonSet. One Cluster Agent asks the API server, so hundreds of nodes do not.

Metrics

Types and what is computed where

TypeThe Agent doesMeaningCustom metrics by default
CountAdds up 10 secondsHow many1 per combination
GaugeKeeps the last valueHow much now1
SetCounts different valuesHow many different1
HistogramComputes avg, count, median, p95, max on this hostPer host only5
DistributionSends the raw values of the intervalPercentiles over all hosts5, and 5 more with percentiles
A combination is one unique set of tag values, including the host.

A host's p95 cannot be averaged with another host's p95. A distribution solves it: the values go into a DDSketch, a set of counters whose buckets grow by a fixed factor. Two sketches are merged by adding the counters, and every percentile stays within a chosen relative error. The open source versions use 1% by default.

DDSketch: which bucket?

γ=1+α1−α=1.010.99≈1.0202i=⌈log⁡γx⌉\gamma = \frac{1+\alpha}{1-\alpha} = \frac{1.01}{0.99} \approx 1.0202 \qquad i = \lceil \log_\gamma x \rceil
With alpha = 1%, all values from 1 ms to 1 minute (a factor of 60,000) need ln(60,000) / ln(1.0202), about 550 buckets.

How a metric query is answered

  1. 1

    Choose series

    By name and tags: avg:system.cpu.user{env:prod} by {service}.

  2. 2

    Over time

    Points of one series are combined per interval (rollup). The default is the average, so short peaks disappear over long ranges.

  3. 3

    Over space

    Series are combined by the aggregator in front, here the average over hosts.

  4. 4

    Functions

    For example .as_count(), or .rollup(max, 60) if you care about peaks.

Tags

Three tags that join everything

env, service and version are the unified service tags. Set them once, in the Agent, the container labels and the tracer (DD_ENV, DD_SERVICE, DD_VERSION). Then a chart, a trace and a log line of one release find each other, and you can compare two versions during a rollout.

Good tags

  • env, service, version, region, team
  • Values you can list on one page
  • Lower case: tags are normalized
  • Added by the Agent, not by every developer

Bad tags

  • User, order or request ids
  • Timestamps, full URLs, error texts
  • A different key in each team for the same thing
  • Personal data

Custom metrics of one timer

20 hosts×30 endpoints×4 status classes=2,4002,400×10=24,00020\ \text{hosts} \times 30\ \text{endpoints} \times 4\ \text{status classes} = 2{,}400 \qquad 2{,}400 \times 10 = 24{,}000
As a distribution with percentiles: 5 plus 5 per combination. Assumed numbers, worst case. Without the host tag it is 1,200. The decision: is the host needed on this metric?

Under the cardinality model, the number of unique combinations is averaged over the hours of a month. Accounts include an allowance per host. Metrics without Limits separates ingesting from indexing: you send all tags, but keep only a list of them queryable. Some contracts use another model, Metric Name pricing, which counts names and data points. Read which one you have before you optimize.

Traces and logs

Keep less than you receive

Which traces stay?

By default the Agent aims at 10 traces a second, spread over services by traffic, and 10 a second with errors.

How long things stay, by default

DataTime
Metrics: tags and values15 months
Indexed spans15 or 30 days, by plan
Service and resource statistics30 days
LogsBy plan and index
Audit trail, if enabled90 days

The way of a log line

A filtered line can still be archived, seen live, and counted.

Typical rule: index all errors, 5% of successful requests, none of the health checks, and archive everything in your own object storage. From the archive you can load a time range back when a case needs it. How traces work is on Jaeger.

Alerts

Monitors that people trust

ChoiceQuestionTypical answer
Scope and groupOne alert for all or per service?Per service, so a message has an owner
Threshold and recoveryWhen is it over?Alert above 5%, recover below 3%, against flapping
WindowHow long must it last?5 to 10 minutes for error shares
Missing dataWhat if nothing arrives?Notify for hosts that must report; show OK for error counts
New groupsDoes a starting container alert?A delay for new groups
The options for missing data: evaluate as zero or last status, show no data, notify, or show OK.
Text
# Monitor query: share of errors over 10 minutes, per servicesum(last_10m):  sum:trace.http.request.errors{env:prod} by {service}.as_count()  / sum:trace.http.request.hits{env:prod} by {service}.as_count()> 0.05
Metric names of traces depend on the library and the operation. Read yours in the metrics list.

Their side

What is known about the inside

Datadog's engineers write about some parts. Husky stores events such as logs and traces as columns in object storage, with metadata in FoundationDB, so computing and storing scale apart. The real-time store for metrics reads from Kafka partitions into one storage shard per core, and is written in Rust. Percentiles use DDSketch. Everything else is not public, and this page does not guess.

The outage of 8 March 2023, from the company's report

Time (UTC)What happened
06:00An automatic security update to systemd starts on many virtual machines
06:00 to 07:00A restarted network service deletes routes; tens of thousands of nodes go offline
06:31First public status update
09:13Web access restored
16:44First major service declared operational
9 March, 08:58All services operational in all regions
10 March, 06:25Resolved, historical data filled in
Five regions without a network connection between them failed in the same hour, because the update window was the same clock time. Monitors were unavailable and did not alert.

Operate

Security, sites and leaving

  1. 1

    Choose the site first

    US1, US3, US5, EU1, AP1, AP2, UK1 and two for the US government. They are independent, and data cannot be shared across them.

  2. 2

    Protect the keys

    An API key can send data, an application key can read and change. Store both in a secrets manager and rotate them.

  3. 3

    Remove personal data early

    Mask in the Agent, before it leaves your network. Masking later protects less.

  4. 4

    Limit the ports

    DogStatsD and traces accept anything, so they must be reachable only by your applications.

  5. 5

    Keep a way out

    Instrument with OpenTelemetry where you can. Datadog accepts OTLP. Dashboards and monitors as Terraform show what would have to be rebuilt.

Already have Prometheus pages? The Agent can read them with the OpenMetrics check, by default up to 2,000 metrics per instance. They then count as custom metrics.

Cost

What drives the bill

ProductCountedLever
Infrastructure, APMHosts per hour; the high watermark plan bills the highest of the lower 99% of hoursFewer, larger hosts; a monthly plus hourly plan for strong swings
ContainersThose above an allowance per hostFewer sidecars
Custom metricsUnique combinations, or names and pointsDrop tags, Metrics without Limits
LogsBytes received, events indexed, days keptExclusion filters, archive
TracesBytes received, spans indexedSampling, retention filters
Prices are left out on purpose: they depend on plan, site and contract.

The billed hosts of a month

720 hours×1%=7.2⇒about 7 hours of peak are ignored720\ \text{hours} \times 1\% = 7.2 \Rightarrow \text{about 7 hours of peak are ignored}
A 4 hour sale with 300 hosts instead of 100 is free under the high watermark plan. Doing it every Friday for 4 hours (16 hours) bills 300 hosts for the month.

Decide

When to choose it, and when not

Buy or run?

Choose it when

  • A small team needs all signals this week
  • Many different technologies need ready integrations
  • Jumping between metrics, traces and logs saves incident time
  • Monitoring should not depend on your own platform

Look elsewhere when

  • Data must stay inside
  • You have many small hosts or very many tags
  • A platform team already runs Prometheus well
  • You want a fixed cost, or an easy exit

Neighbours

ProductAlikeDifferent
PrometheusLabelled metrics, alertsYou run it; it pulls; metrics only
GrafanaDashboards, alertsDraws data from stores; does not collect
ELK StackLog searchYou run it or rent it; search first
OpenTelemetryCollects all signalsA standard and a collector, no store and no screens

Summary

The whole topic in one minute.

Datadog is a push system with a helper on every host: the Agent collects every 15 seconds, flushes application metrics every 10, buffers when the network fails, and sends out over HTTPS. Use the three tags env, service and version on everything.

The cost driver is how many different tag combinations, hosts, log events and traces you send and keep. Keep ids out of tags, index only useful logs, sample traces on purpose, and keep a small check of your own for the day when the service is down.

  • One Agent per host pushes outwards; nothing connects in.
  • Checks every 15 s, DogStatsD flush every 10 s, a buffer for network gaps.
  • Histogram is per host, distribution is over all hosts.
  • env, service and version on everything; never ids.
  • Ingesting and indexing are two decisions.
  • Cost follows hosts, combinations, events and days. Keep one independent check.

Sources