๐Ÿ”ง DevOps

Datadog

A cloud monitoring and security platform

Detailed Explanation

Datadog is a SaaS platform that provides integrated monitoring of cloud-scale infrastructure, applications, and logs. Founded in 2010, it is one of the most widely used commercial monitoring solutions today, offering the three pillars of observability โ€” metrics, logs, and traces โ€” in a single platform.

Key Features

  • Infrastructure Monitoring: Collects metrics from servers, containers, and cloud services
  • APM (Application Performance Monitoring): Tracks request flows with distributed tracing
  • Log Management: Log collection, parsing, and analysis
  • RUM (Real User Monitoring): Measures real user experience
  • Synthetics: API and browser-based synthetic monitoring
  • Security Monitoring: Security event detection and SIEM

Datadog Agent Architecture

  • Datadog Agent: Metrics/log collector that runs on the host
  • DogStatsD: Daemon for sending custom metrics
  • Trace Agent: APM trace collector
  • Process Agent: Process-level monitoring

Code Example

datadog.yaml - Agent configuration

# /etc/datadog-agent/datadog.yaml
api_key: "your-api-key-here"
site: "datadoghq.com"  # EU๋Š” datadoghq.eu

# ํ˜ธ์ŠคํŠธ ํƒœ๊ทธ ์„ค์ •
tags:
  - env:production
  - service:api-server
  - team:platform

# APM ์„ค์ •
apm_config:
  enabled: true
  apm_dd_url: https://trace.agent.datadoghq.com

# ๋กœ๊ทธ ์ˆ˜์ง‘ ํ™œ์„ฑํ™”
logs_enabled: true
logs_config:
  container_collect_all: true
  processing_rules:
    - type: exclude_at_match
      name: exclude_healthchecks
      pattern: "GET /health"

# ํ”„๋กœ์„ธ์Šค ๋ชจ๋‹ˆํ„ฐ๋ง
process_config:
  enabled: true
  container_collection:
    enabled: true

# DogStatsD ์„ค์ •
dogstatsd_port: 8125
dogstatsd_non_local_traffic: true

Kubernetes integration configuration

# datadog-values.yaml - Helm Chart ์„ค์ •
datadog:
  apiKey: ${DD_API_KEY}
  appKey: ${DD_APP_KEY}
  site: datadoghq.com

  # ํด๋Ÿฌ์Šคํ„ฐ ์ด๋ฆ„
  clusterName: production-k8s

  # ํƒœ๊ทธ
  tags:
    - env:production
    - region:ap-northeast-2

  # APM ํ™œ์„ฑํ™”
  apm:
    portEnabled: true
    socketEnabled: true

  # ๋กœ๊ทธ ์ˆ˜์ง‘
  logs:
    enabled: true
    containerCollectAll: true

  # ํ”„๋กœ์„ธ์Šค ๋ชจ๋‹ˆํ„ฐ๋ง
  processAgent:
    enabled: true
    processCollection: true

# ํด๋Ÿฌ์Šคํ„ฐ ์—์ด์ „ํŠธ
clusterAgent:
  enabled: true
  metricsProvider:
    enabled: true  # HPA ์—ฐ๋™

# Node Agent
agents:
  rbac:
    create: true
  containers:
    agent:
      resources:
        requests:
          memory: "256Mi"
          cpu: "200m"

Application APM integration (Python)

# Flask ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ APM ์—ฐ๋™
from ddtrace import tracer, patch_all

# ์ž๋™ ํŒจ์น˜
patch_all()

# ์ปค์Šคํ…€ ์„ค์ •
tracer.configure(
    hostname='localhost',
    port=8126,
    service='my-flask-app',
    env='production',
)

from flask import Flask
from datadog import statsd

app = Flask(__name__)

@app.route('/api/users/')
def get_user(user_id):
    # ์ปค์Šคํ…€ ์ŠคํŒฌ ์ถ”๊ฐ€
    with tracer.trace('database.query', service='postgresql') as span:
        span.set_tag('user.id', user_id)
        user = fetch_user_from_db(user_id)

    # ์ปค์Šคํ…€ ๋ฉ”ํŠธ๋ฆญ ์ „์†ก
    statsd.increment('api.users.get', tags=['endpoint:get_user'])

    return jsonify(user)

# DogStatsD ์ปค์Šคํ…€ ๋ฉ”ํŠธ๋ฆญ
from datadog import initialize, statsd

initialize(statsd_host='localhost', statsd_port=8125)

# ์นด์šดํ„ฐ
statsd.increment('page.views', tags=['page:home'])

# ๊ฒŒ์ด์ง€
statsd.gauge('queue.size', queue.size(), tags=['queue:orders'])

# ํžˆ์Šคํ† ๊ทธ๋žจ
statsd.histogram('request.latency', response_time, tags=['endpoint:api'])

Practical Conversation Example

SRE Engineer
"We're getting intermittent 500 errors in production, and I can't figure out the cause from the logs alone."
Senior SRE
"I'll check the traces for that time window in Datadog APM. If I filter by Error status... there it is. A timeout is occurring on a specific DB query. Following the trace, this query is taking more than 5 seconds."
SRE Engineer
"Wow, how did you find it so fast?"
Senior SRE
"If you look at the duration of each span in the APM Trace, the bottleneck is immediately visible. You can also see at a glance in the Service Map that this service depends on the DB. I think we need to add an index to this query or adjust the timeout settings."

Cautions

Cost Management

Datadog incurs costs based on the number of hosts, log volume, and number of custom metrics. Manage log indexing policies and metric cardinality carefully.

API key security

If an API key is exposed, malicious data transmission or billing issues can occur. Manage it securely through Secrets Manager.

Agent Resources

The Datadog Agent uses a certain amount of CPU/memory. In resource-constrained environments, optimize the Agent configuration.

Cardinality Explosion

Using unique IDs (user ID, session ID) directly as tags causes metric cardinality to grow explosively. Use appropriate bucketing.

Learn More