Datadog Cheat Sheet

Datadog is a monitoring and analytics platform that provides insights into the performance of applications, systems, and infrastructure. Here’s a cheat sheet for Datadog commands and configurations:

Datadog Metrics and Tags

Send a Custom Metric with Tags (Python Example):

from datadog import initialize, api

options = {
    'api_key': 'YOUR_API_KEY',
    'app_key': 'YOUR_APP_KEY'
}

initialize(**options)

api.Metric.send(metric='custom.metric', points=1, host='hostname', tags=['tag1:value1', 'tag2:value2'])

Query Metrics with Tags in the Dashboard:

avg:custom.metric{*} by {tag1, tag2}

Datadog Dashboards

Create a Dashboard:

  • Login to Datadog, go to Dashboards, and click on “New Dashboard.”

Add Widgets to Dashboard:

  • Click on “Add Widgets” and select the desired visualization.

Customize Widgets:

  • Adjust widget settings, set metrics, and define tag filters.

Set Up Alerting Widgets:

  • Create alerting widgets based on thresholds and conditions.

Datadog Monitors

Create a Monitor:

  • Navigate to Monitors, click “New Monitor,” and configure thresholds.

Use Advanced Monitor Options:

  • Leverage advanced options like anomaly detection, multi-alert conditions, and custom queries.

Datadog APM (Application Performance Monitoring)

Instrument Code for APM (Python Example):

from ddtrace import tracer

@tracer.wrap(service='my-service', span_type='web')
def my_function():
    # Function code

Analyze Trace in Datadog UI:

  • Go to APM, select your service, and inspect traces.

Datadog Logs

Send Logs to Datadog (Python Example):

import logging
from datadog import initialize, api

options = {
    'api_key': 'YOUR_API_KEY',
    'app_key': 'YOUR_APP_KEY'
}

initialize(**options)

logger = logging.getLogger('my_logger')
logger.addHandler(logging.StreamHandler())
logger.addHandler(api.DatadogHandler())

Search and Filter Logs:

  • Use the Log Explorer to search and filter logs.

Datadog APIs

Query Datadog Metrics via API:

curl -G "https://api.datadoghq.com/api/v1/query" \
     -H "Content-Type: application/json" \
     -H "DD-API-KEY: YOUR_API_KEY" \
     -H "DD-APPLICATION-KEY: YOUR_APP_KEY" \
     --data-urlencode "query=avg:system.cpu.idle{*}"

Query Datadog Logs via API:

curl -G "https://api.datadoghq.com/api/v1/logs-queries/list" \
     -H "Content-Type: application/json" \
     -H "DD-API-KEY: YOUR_API_KEY" \
     -H "DD-APPLICATION-KEY: YOUR_APP_KEY"

Datadog Integration

  • Integrate Datadog with AWS:
    • Follow the AWS integration guide to collect metrics and logs.
  • Integrate Datadog with Kubernetes:
    • Use the Datadog Helm chart or deploy the Agent as a DaemonSet.
  • Integrate Datadog with Docker:
    • Set up the Datadog Agent on your Docker hosts.

This cheat sheet provides a starting point for using Datadog for monitoring and observability. For more details and advanced configurations, refer to the official Datadog documentation.