$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill datadogImplement Datadog monitoring and APM for infrastructure and applications. Configure agents, create dashboards, set up alerts, and implement distributed tracing. Use when implementing enterprise monitoring, APM, or unified observability platforms.
| 1 | # Datadog |
| 2 | |
| 3 | Monitor infrastructure and applications with Datadog's unified observability platform. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Implementing enterprise-grade monitoring |
| 9 | - Setting up APM and distributed tracing |
| 10 | - Creating unified dashboards for infrastructure and apps |
| 11 | - Configuring intelligent alerting |
| 12 | - Monitoring cloud infrastructure (AWS, Azure, GCP) |
| 13 | |
| 14 | ## Prerequisites |
| 15 | |
| 16 | - Datadog account and API key |
| 17 | - Agent installation access |
| 18 | - Application code access for APM |
| 19 | |
| 20 | ## Agent Installation |
| 21 | |
| 22 | ### Linux |
| 23 | |
| 24 | ```bash |
| 25 | # Install agent |
| 26 | DD_API_KEY=<YOUR_API_KEY> DD_SITE="datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script_agent7.sh)" |
| 27 | |
| 28 | # Or via package manager |
| 29 | apt-get update && apt-get install datadog-agent |
| 30 | |
| 31 | # Configure API key |
| 32 | echo "api_key: YOUR_API_KEY" >> /etc/datadog-agent/datadog.yaml |
| 33 | |
| 34 | # Start agent |
| 35 | systemctl start datadog-agent |
| 36 | systemctl enable datadog-agent |
| 37 | ``` |
| 38 | |
| 39 | ### Docker |
| 40 | |
| 41 | ```yaml |
| 42 | # docker-compose.yml |
| 43 | version: '3.8' |
| 44 | |
| 45 | services: |
| 46 | datadog-agent: |
| 47 | image: gcr.io/datadoghq/agent:7 |
| 48 | environment: |
| 49 | - DD_API_KEY=${DD_API_KEY} |
| 50 | - DD_SITE=datadoghq.com |
| 51 | - DD_LOGS_ENABLED=true |
| 52 | - DD_APM_ENABLED=true |
| 53 | - DD_PROCESS_AGENT_ENABLED=true |
| 54 | volumes: |
| 55 | - /var/run/docker.sock:/var/run/docker.sock:ro |
| 56 | - /proc/:/host/proc/:ro |
| 57 | - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro |
| 58 | ports: |
| 59 | - "8126:8126" # APM |
| 60 | - "8125:8125/udp" # DogStatsD |
| 61 | ``` |
| 62 | |
| 63 | ### Kubernetes |
| 64 | |
| 65 | ```bash |
| 66 | # Using Helm |
| 67 | helm repo add datadog https://helm.datadoghq.com |
| 68 | |
| 69 | helm install datadog datadog/datadog \ |
| 70 | --set datadog.apiKey=${DD_API_KEY} \ |
| 71 | --set datadog.site=datadoghq.com \ |
| 72 | --set datadog.logs.enabled=true \ |
| 73 | --set datadog.apm.portEnabled=true \ |
| 74 | --set datadog.processAgent.enabled=true \ |
| 75 | --namespace datadog \ |
| 76 | --create-namespace |
| 77 | ``` |
| 78 | |
| 79 | ## Agent Configuration |
| 80 | |
| 81 | ```yaml |
| 82 | # /etc/datadog-agent/datadog.yaml |
| 83 | api_key: YOUR_API_KEY |
| 84 | site: datadoghq.com |
| 85 | |
| 86 | # Hostname |
| 87 | hostname: myserver.example.com |
| 88 | |
| 89 | # Tags applied to all metrics |
| 90 | tags: |
| 91 | - env:production |
| 92 | - service:myapp |
| 93 | - team:platform |
| 94 | |
| 95 | # Log collection |
| 96 | logs_enabled: true |
| 97 | |
| 98 | # APM |
| 99 | apm_config: |
| 100 | enabled: true |
| 101 | apm_dd_url: https://trace.agent.datadoghq.com |
| 102 | |
| 103 | # Process monitoring |
| 104 | process_config: |
| 105 | enabled: true |
| 106 | |
| 107 | # Container monitoring |
| 108 | container_collect_all: true |
| 109 | docker_labels_as_tags: |
| 110 | app: service |
| 111 | environment: env |
| 112 | ``` |
| 113 | |
| 114 | ## Integration Configuration |
| 115 | |
| 116 | ### MySQL |
| 117 | |
| 118 | ```yaml |
| 119 | # /etc/datadog-agent/conf.d/mysql.d/conf.yaml |
| 120 | init_config: |
| 121 | |
| 122 | instances: |
| 123 | - host: localhost |
| 124 | port: 3306 |
| 125 | username: datadog |
| 126 | password: <PASSWORD> |
| 127 | tags: |
| 128 | - env:production |
| 129 | options: |
| 130 | replication: true |
| 131 | extra_status_metrics: true |
| 132 | ``` |
| 133 | |
| 134 | ### PostgreSQL |
| 135 | |
| 136 | ```yaml |
| 137 | # /etc/datadog-agent/conf.d/postgres.d/conf.yaml |
| 138 | init_config: |
| 139 | |
| 140 | instances: |
| 141 | - host: localhost |
| 142 | port: 5432 |
| 143 | username: datadog |
| 144 | password: <PASSWORD> |
| 145 | dbname: mydb |
| 146 | collect_activity_metrics: true |
| 147 | collect_database_size_metrics: true |
| 148 | ``` |
| 149 | |
| 150 | ### NGINX |
| 151 | |
| 152 | ```yaml |
| 153 | # /etc/datadog-agent/conf.d/nginx.d/conf.yaml |
| 154 | init_config: |
| 155 | |
| 156 | instances: |
| 157 | - nginx_status_url: http://localhost:80/nginx_status |
| 158 | tags: |
| 159 | - env:production |
| 160 | ``` |
| 161 | |
| 162 | ## Log Collection |
| 163 | |
| 164 | ### File-Based Logs |
| 165 | |
| 166 | ```yaml |
| 167 | # /etc/datadog-agent/conf.d/myapp.d/conf.yaml |
| 168 | logs: |
| 169 | - type: file |
| 170 | path: /var/log/myapp/*.log |
| 171 | service: myapp |
| 172 | source: python |
| 173 | sourcecategory: custom |
| 174 | tags: |
| 175 | - env:production |
| 176 | |
| 177 | - type: file |
| 178 | path: /var/log/nginx/access.log |
| 179 | service: nginx |
| 180 | source: nginx |
| 181 | log_processing_rules: |
| 182 | - type: exclude_at_match |
| 183 | name: exclude_healthchecks |
| 184 | pattern: health_check |
| 185 | ``` |
| 186 | |
| 187 | ### Docker Logs |
| 188 | |
| 189 | ```yaml |
| 190 | # docker-compose.yml |
| 191 | services: |
| 192 | myapp: |
| 193 | labels: |
| 194 | com.datadoghq.ad.logs: '[{"source": "python", "service": "myapp"}]' |
| 195 | ``` |
| 196 | |
| 197 | ### Kubernetes Logs |
| 198 | |
| 199 | ```yaml |
| 200 | # Pod annotation |
| 201 | apiVersion: v1 |
| 202 | kind: Pod |
| 203 | metadata: |
| 204 | annotations: |
| 205 | ad.datadoghq.com/myapp.logs: | |
| 206 | [{ |
| 207 | "source": "python", |
| 208 | "service": "myapp", |
| 209 | "log_processing_rules": [{ |
| 210 | "type": "multi_line", |
| 211 | "name": "python_tracebacks", |
| 212 | "pattern": "^Traceback" |
| 213 | }] |
| 214 | }] |
| 215 | ``` |
| 216 | |
| 217 | ## APM Configuration |
| 218 | |
| 219 | ### Python |
| 220 | |
| 221 | ```python |
| 222 | from ddtrace import patch_all, tracer |
| 223 | |
| 224 | # Automatic instrumentation |
| 225 | patch_all() |
| 226 | |
| 227 | # Configure tracer |
| 228 | tracer.configure( |
| 229 | hostname='localhost', |
| 230 | port=8126, |
| 231 | service='myapp', |
| 232 | env='production', |
| 233 | version='1.0.0' |
| 234 | ) |
| 235 | |
| 236 | # Manual instrumentation |
| 237 | @tracer.wrap(service='myapp', resource='process_order') |
| 238 | def process_order(order_id): |
| 239 | with tracer.trace('validate_order') as span: |
| 240 | span.set_tag('order_id', order_id) |
| 241 | # Validation logic |
| 242 | |
| 243 | with tracer.trace('save_order'): |
| 244 | # Save logic |