Datadog
medium 27 minDatadog is a hosted monitoring platform.
Video lesson · Chapter 1 of 5
Trace a checkout measurement before trusting its alert
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
2010
Olivier Pomel and Alexis Le-Quoc found the company in New York.
2015 and later
Purchases extend the platform, among them Mortar Data in 2015 and a log service, Logmatic, in 2017.
September 2019
The company goes public on Nasdaq. In the same month its engineers publish DDSketch, a structure for percentiles that can be merged.
May 2022
It describes Husky, its third-generation event store on object storage.
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.
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.
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
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
| Port | Use | Open to |
|---|---|---|
| 8125 UDP | DogStatsD metrics from your code | This host or node only |
| 8126 TCP | Traces | This host or node only |
| 5000, 5001 | The Agent's own state and commands | This host only |
| 443 out | Most data to Datadog | The outside, only outwards |
# /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: 2147483648How long does the buffer last?
In Kubernetes
Metrics
Types and what is computed where
| Type | The Agent does | Meaning | Custom metrics by default |
|---|---|---|---|
| Count | Adds up 10 seconds | How many | 1 per combination |
| Gauge | Keeps the last value | How much now | 1 |
| Set | Counts different values | How many different | 1 |
| Histogram | Computes avg, count, median, p95, max on this host | Per host only | 5 |
| Distribution | Sends the raw values of the interval | Percentiles over all hosts | 5, and 5 more with percentiles |
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?
How a metric query is answered
- 1
Choose series
By name and tags:
avg:system.cpu.user{env:prod} by {service}. - 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
Over space
Series are combined by the aggregator in front, here the average over hosts.
- 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
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?
How long things stay, by default
| Data | Time |
|---|---|
| Metrics: tags and values | 15 months |
| Indexed spans | 15 or 30 days, by plan |
| Service and resource statistics | 30 days |
| Logs | By plan and index |
| Audit trail, if enabled | 90 days |
The way of a log line
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
| Choice | Question | Typical answer |
|---|---|---|
| Scope and group | One alert for all or per service? | Per service, so a message has an owner |
| Threshold and recovery | When is it over? | Alert above 5%, recover below 3%, against flapping |
| Window | How long must it last? | 5 to 10 minutes for error shares |
| Missing data | What if nothing arrives? | Notify for hosts that must report; show OK for error counts |
| New groups | Does a starting container alert? | A delay for new groups |
# 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.05Their 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:00 | An automatic security update to systemd starts on many virtual machines |
| 06:00 to 07:00 | A restarted network service deletes routes; tens of thousands of nodes go offline |
| 06:31 | First public status update |
| 09:13 | Web access restored |
| 16:44 | First major service declared operational |
| 9 March, 08:58 | All services operational in all regions |
| 10 March, 06:25 | Resolved, historical data filled in |
Operate
Security, sites and leaving
- 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
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
Remove personal data early
Mask in the Agent, before it leaves your network. Masking later protects less.
- 4
Limit the ports
DogStatsD and traces accept anything, so they must be reachable only by your applications.
- 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
| Product | Counted | Lever |
|---|---|---|
| Infrastructure, APM | Hosts per hour; the high watermark plan bills the highest of the lower 99% of hours | Fewer, larger hosts; a monthly plus hourly plan for strong swings |
| Containers | Those above an allowance per host | Fewer sidecars |
| Custom metrics | Unique combinations, or names and points | Drop tags, Metrics without Limits |
| Logs | Bytes received, events indexed, days kept | Exclusion filters, archive |
| Traces | Bytes received, spans indexed | Sampling, retention filters |
The billed hosts of a 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
| Product | Alike | Different |
|---|---|---|
| Prometheus | Labelled metrics, alerts | You run it; it pulls; metrics only |
| Grafana | Dashboards, alerts | Draws data from stores; does not collect |
| ELK Stack | Log search | You run it or rent it; search first |
| OpenTelemetry | Collects all signals | A 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
- Datadog: Agent architecture
- Datadog: network, ports and buffering
- Datadog: DogStatsD data aggregation
- Datadog: distributions
- Datadog: custom metrics billing
- Datadog: pricing plans
- Datadog: trace ingestion
- Datadog: data retention periods
- Datadog: monitor configuration
- Datadog: sites
- Datadog: report on 8 March 2023
- Datadog: introducing Husky
- Datadog: accurate percentiles with DDSketch
- Datadog: timeseries storage in Rust