chub-dev 0.1.0 → 0.1.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/bin/chub-mcp +2 -0
- package/dist/airtable/docs/database/javascript/DOC.md +1437 -0
- package/dist/airtable/docs/database/python/DOC.md +1735 -0
- package/dist/amplitude/docs/analytics/javascript/DOC.md +1282 -0
- package/dist/amplitude/docs/analytics/python/DOC.md +1199 -0
- package/dist/anthropic/docs/claude-api/javascript/DOC.md +503 -0
- package/dist/anthropic/docs/claude-api/python/DOC.md +389 -0
- package/dist/asana/docs/tasks/DOC.md +1396 -0
- package/dist/assemblyai/docs/transcription/DOC.md +1043 -0
- package/dist/atlassian/docs/confluence/javascript/DOC.md +1347 -0
- package/dist/atlassian/docs/confluence/python/DOC.md +1604 -0
- package/dist/auth0/docs/identity/javascript/DOC.md +968 -0
- package/dist/auth0/docs/identity/python/DOC.md +1199 -0
- package/dist/aws/docs/s3/javascript/DOC.md +1773 -0
- package/dist/aws/docs/s3/python/DOC.md +1807 -0
- package/dist/binance/docs/trading/javascript/DOC.md +1315 -0
- package/dist/binance/docs/trading/python/DOC.md +1454 -0
- package/dist/braintree/docs/gateway/javascript/DOC.md +1278 -0
- package/dist/braintree/docs/gateway/python/DOC.md +1179 -0
- package/dist/chromadb/docs/embeddings-db/javascript/DOC.md +1263 -0
- package/dist/chromadb/docs/embeddings-db/python/DOC.md +1707 -0
- package/dist/clerk/docs/auth/javascript/DOC.md +1220 -0
- package/dist/clerk/docs/auth/python/DOC.md +274 -0
- package/dist/cloudflare/docs/workers/javascript/DOC.md +918 -0
- package/dist/cloudflare/docs/workers/python/DOC.md +994 -0
- package/dist/cockroachdb/docs/distributed-db/DOC.md +1500 -0
- package/dist/cohere/docs/llm/DOC.md +1335 -0
- package/dist/datadog/docs/monitoring/javascript/DOC.md +1740 -0
- package/dist/datadog/docs/monitoring/python/DOC.md +1815 -0
- package/dist/deepgram/docs/speech/javascript/DOC.md +885 -0
- package/dist/deepgram/docs/speech/python/DOC.md +685 -0
- package/dist/deepl/docs/translation/javascript/DOC.md +887 -0
- package/dist/deepl/docs/translation/python/DOC.md +944 -0
- package/dist/deepseek/docs/llm/DOC.md +1220 -0
- package/dist/directus/docs/headless-cms/javascript/DOC.md +1128 -0
- package/dist/directus/docs/headless-cms/python/DOC.md +1276 -0
- package/dist/discord/docs/bot/javascript/DOC.md +1090 -0
- package/dist/discord/docs/bot/python/DOC.md +1130 -0
- package/dist/elasticsearch/docs/search/DOC.md +1634 -0
- package/dist/elevenlabs/docs/text-to-speech/javascript/DOC.md +336 -0
- package/dist/elevenlabs/docs/text-to-speech/python/DOC.md +552 -0
- package/dist/firebase/docs/auth/DOC.md +1015 -0
- package/dist/gemini/docs/genai/javascript/DOC.md +691 -0
- package/dist/gemini/docs/genai/python/DOC.md +555 -0
- package/dist/github/docs/octokit/DOC.md +1560 -0
- package/dist/google/docs/bigquery/javascript/DOC.md +1688 -0
- package/dist/google/docs/bigquery/python/DOC.md +1503 -0
- package/dist/hubspot/docs/crm/javascript/DOC.md +1805 -0
- package/dist/hubspot/docs/crm/python/DOC.md +2033 -0
- package/dist/huggingface/docs/transformers/DOC.md +948 -0
- package/dist/intercom/docs/messaging/javascript/DOC.md +1844 -0
- package/dist/intercom/docs/messaging/python/DOC.md +1797 -0
- package/dist/jira/docs/issues/javascript/DOC.md +1420 -0
- package/dist/jira/docs/issues/python/DOC.md +1492 -0
- package/dist/kafka/docs/streaming/javascript/DOC.md +1671 -0
- package/dist/kafka/docs/streaming/python/DOC.md +1464 -0
- package/dist/landingai-ade/docs/api/DOC.md +620 -0
- package/dist/landingai-ade/docs/sdk/python/DOC.md +489 -0
- package/dist/landingai-ade/docs/sdk/typescript/DOC.md +542 -0
- package/dist/landingai-ade/skills/SKILL.md +489 -0
- package/dist/launchdarkly/docs/feature-flags/javascript/DOC.md +1191 -0
- package/dist/launchdarkly/docs/feature-flags/python/DOC.md +1671 -0
- package/dist/linear/docs/tracker/DOC.md +1554 -0
- package/dist/livekit/docs/realtime/javascript/DOC.md +303 -0
- package/dist/livekit/docs/realtime/python/DOC.md +163 -0
- package/dist/mailchimp/docs/marketing/DOC.md +1420 -0
- package/dist/meilisearch/docs/search/DOC.md +1241 -0
- package/dist/microsoft/docs/onedrive/javascript/DOC.md +1421 -0
- package/dist/microsoft/docs/onedrive/python/DOC.md +1549 -0
- package/dist/mongodb/docs/atlas/DOC.md +2041 -0
- package/dist/notion/docs/workspace-api/javascript/DOC.md +1435 -0
- package/dist/notion/docs/workspace-api/python/DOC.md +1400 -0
- package/dist/okta/docs/identity/javascript/DOC.md +1171 -0
- package/dist/okta/docs/identity/python/DOC.md +1401 -0
- package/dist/openai/docs/chat/javascript/DOC.md +407 -0
- package/dist/openai/docs/chat/python/DOC.md +568 -0
- package/dist/paypal/docs/checkout/DOC.md +278 -0
- package/dist/pinecone/docs/sdk/javascript/DOC.md +984 -0
- package/dist/pinecone/docs/sdk/python/DOC.md +1395 -0
- package/dist/plaid/docs/banking/javascript/DOC.md +1163 -0
- package/dist/plaid/docs/banking/python/DOC.md +1203 -0
- package/dist/playwright-community/skills/login-flows/SKILL.md +108 -0
- package/dist/postmark/docs/transactional-email/DOC.md +1168 -0
- package/dist/prisma/docs/orm/javascript/DOC.md +1419 -0
- package/dist/prisma/docs/orm/python/DOC.md +1317 -0
- package/dist/qdrant/docs/vector-search/javascript/DOC.md +1221 -0
- package/dist/qdrant/docs/vector-search/python/DOC.md +1653 -0
- package/dist/rabbitmq/docs/message-queue/javascript/DOC.md +1193 -0
- package/dist/rabbitmq/docs/message-queue/python/DOC.md +1243 -0
- package/dist/razorpay/docs/payments/javascript/DOC.md +1219 -0
- package/dist/razorpay/docs/payments/python/DOC.md +1330 -0
- package/dist/redis/docs/key-value/javascript/DOC.md +1851 -0
- package/dist/redis/docs/key-value/python/DOC.md +2054 -0
- package/dist/registry.json +2817 -0
- package/dist/replicate/docs/model-hosting/DOC.md +1318 -0
- package/dist/resend/docs/email/DOC.md +1271 -0
- package/dist/salesforce/docs/crm/javascript/DOC.md +1241 -0
- package/dist/salesforce/docs/crm/python/DOC.md +1183 -0
- package/dist/search-index.json +1 -0
- package/dist/sendgrid/docs/email-api/javascript/DOC.md +371 -0
- package/dist/sendgrid/docs/email-api/python/DOC.md +656 -0
- package/dist/sentry/docs/error-tracking/javascript/DOC.md +1073 -0
- package/dist/sentry/docs/error-tracking/python/DOC.md +1309 -0
- package/dist/shopify/docs/storefront/DOC.md +457 -0
- package/dist/slack/docs/workspace/javascript/DOC.md +933 -0
- package/dist/slack/docs/workspace/python/DOC.md +271 -0
- package/dist/square/docs/payments/javascript/DOC.md +1855 -0
- package/dist/square/docs/payments/python/DOC.md +1728 -0
- package/dist/stripe/docs/api/DOC.md +1727 -0
- package/dist/stripe/docs/payments/DOC.md +1726 -0
- package/dist/stytch/docs/auth/javascript/DOC.md +1813 -0
- package/dist/stytch/docs/auth/python/DOC.md +1962 -0
- package/dist/supabase/docs/client/DOC.md +1606 -0
- package/dist/twilio/docs/messaging/python/DOC.md +469 -0
- package/dist/twilio/docs/messaging/typescript/DOC.md +946 -0
- package/dist/vercel/docs/platform/DOC.md +1940 -0
- package/dist/weaviate/docs/vector-db/javascript/DOC.md +1268 -0
- package/dist/weaviate/docs/vector-db/python/DOC.md +1388 -0
- package/dist/zendesk/docs/support/javascript/DOC.md +2150 -0
- package/dist/zendesk/docs/support/python/DOC.md +2297 -0
- package/package.json +22 -6
- package/skills/get-api-docs/SKILL.md +84 -0
- package/src/commands/annotate.js +83 -0
- package/src/commands/build.js +12 -1
- package/src/commands/feedback.js +150 -0
- package/src/commands/get.js +83 -42
- package/src/commands/search.js +7 -0
- package/src/index.js +43 -17
- package/src/lib/analytics.js +90 -0
- package/src/lib/annotations.js +57 -0
- package/src/lib/bm25.js +170 -0
- package/src/lib/cache.js +69 -6
- package/src/lib/config.js +8 -3
- package/src/lib/identity.js +99 -0
- package/src/lib/registry.js +103 -20
- package/src/lib/telemetry.js +86 -0
- package/src/mcp/server.js +177 -0
- package/src/mcp/tools.js +251 -0
|
@@ -0,0 +1,1815 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: monitoring
|
|
3
|
+
description: "Official Datadog API client for Python to submit metrics, manage monitors, and interact with Datadog observability features."
|
|
4
|
+
metadata:
|
|
5
|
+
languages: "python"
|
|
6
|
+
versions: "2.45.0"
|
|
7
|
+
updated-on: "2026-03-01"
|
|
8
|
+
source: maintainer
|
|
9
|
+
tags: "datadog,monitoring,metrics,observability,apm"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Datadog API Client for Python
|
|
13
|
+
|
|
14
|
+
## Golden Rule
|
|
15
|
+
|
|
16
|
+
**ALWAYS use `datadog-api-client` version 2.45.0 or later.**
|
|
17
|
+
|
|
18
|
+
This is the official Datadog API client for Python. Do NOT use:
|
|
19
|
+
- `datadog` (legacy library, limited functionality)
|
|
20
|
+
- `datadogpy` (old library, use datadog-api-client instead)
|
|
21
|
+
- Direct HTTP calls to Datadog API endpoints (use the official client instead)
|
|
22
|
+
|
|
23
|
+
The `datadog-api-client` package provides complete access to both v1 and v2 Datadog APIs with full type hints and async support.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### Basic Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install datadog-api-client
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### With Async Support
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install datadog-api-client[async]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Requirements
|
|
40
|
+
|
|
41
|
+
- Python 3.8 or higher
|
|
42
|
+
|
|
43
|
+
### Environment Variables
|
|
44
|
+
|
|
45
|
+
Set up your Datadog API credentials as environment variables:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
export DD_API_KEY="your-api-key-here"
|
|
49
|
+
export DD_APP_KEY="your-application-key-here"
|
|
50
|
+
export DD_SITE="datadoghq.com" # Optional: defaults to US site
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For EU region:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
export DD_SITE="datadoghq.eu"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Initialization
|
|
60
|
+
|
|
61
|
+
### Basic Initialization with Environment Variables
|
|
62
|
+
|
|
63
|
+
The client automatically reads `DD_API_KEY` and `DD_APP_KEY` environment variables:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from datadog_api_client import ApiClient, Configuration
|
|
67
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
68
|
+
|
|
69
|
+
configuration = Configuration()
|
|
70
|
+
|
|
71
|
+
with ApiClient(configuration) as api_client:
|
|
72
|
+
api_instance = MonitorsApi(api_client)
|
|
73
|
+
monitors = api_instance.list_monitors()
|
|
74
|
+
print(monitors)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Manual Authentication
|
|
78
|
+
|
|
79
|
+
Provide credentials explicitly in code:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from datadog_api_client import ApiClient, Configuration
|
|
83
|
+
|
|
84
|
+
configuration = Configuration()
|
|
85
|
+
configuration.api_key["apiKeyAuth"] = "your-api-key-here"
|
|
86
|
+
configuration.api_key["appKeyAuth"] = "your-application-key-here"
|
|
87
|
+
|
|
88
|
+
with ApiClient(configuration) as api_client:
|
|
89
|
+
# Use api_client for API calls
|
|
90
|
+
pass
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Regional Configuration
|
|
94
|
+
|
|
95
|
+
Configure for EU or other regions:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from datadog_api_client import ApiClient, Configuration
|
|
99
|
+
|
|
100
|
+
configuration = Configuration()
|
|
101
|
+
configuration.server_variables["site"] = "datadoghq.eu"
|
|
102
|
+
|
|
103
|
+
with ApiClient(configuration) as api_client:
|
|
104
|
+
# Use api_client for API calls
|
|
105
|
+
pass
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Available sites:
|
|
109
|
+
- `datadoghq.com` (US1 - default)
|
|
110
|
+
- `datadoghq.eu` (EU1)
|
|
111
|
+
- `us3.datadoghq.com` (US3)
|
|
112
|
+
- `us5.datadoghq.com` (US5)
|
|
113
|
+
- `ap1.datadoghq.com` (AP1)
|
|
114
|
+
- `ddog-gov.com` (US1-FED)
|
|
115
|
+
|
|
116
|
+
### Advanced Configuration Options
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from datadog_api_client import ApiClient, Configuration
|
|
120
|
+
|
|
121
|
+
configuration = Configuration()
|
|
122
|
+
configuration.api_key["apiKeyAuth"] = "your-api-key"
|
|
123
|
+
configuration.api_key["appKeyAuth"] = "your-app-key"
|
|
124
|
+
configuration.server_variables["site"] = "datadoghq.com"
|
|
125
|
+
|
|
126
|
+
# Enable debugging
|
|
127
|
+
configuration.debug = True
|
|
128
|
+
|
|
129
|
+
# Set connection timeout
|
|
130
|
+
configuration.connection_timeout = 30
|
|
131
|
+
|
|
132
|
+
# Set read timeout
|
|
133
|
+
configuration.read_timeout = 30
|
|
134
|
+
|
|
135
|
+
with ApiClient(configuration) as api_client:
|
|
136
|
+
# Use api_client for API calls
|
|
137
|
+
pass
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Enable Unstable Operations
|
|
141
|
+
|
|
142
|
+
Some v2 endpoints are marked as unstable and require explicit enablement:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from datadog_api_client import ApiClient, Configuration
|
|
146
|
+
|
|
147
|
+
configuration = Configuration()
|
|
148
|
+
configuration.unstable_operations["list_incidents"] = True
|
|
149
|
+
configuration.unstable_operations["create_incident"] = True
|
|
150
|
+
|
|
151
|
+
with ApiClient(configuration) as api_client:
|
|
152
|
+
# Use unstable operations
|
|
153
|
+
pass
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Async Initialization
|
|
157
|
+
|
|
158
|
+
For asynchronous operations:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
import asyncio
|
|
162
|
+
from datadog_api_client import AsyncApiClient, Configuration
|
|
163
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
164
|
+
|
|
165
|
+
async def main():
|
|
166
|
+
configuration = Configuration()
|
|
167
|
+
|
|
168
|
+
async with AsyncApiClient(configuration) as api_client:
|
|
169
|
+
api_instance = MonitorsApi(api_client)
|
|
170
|
+
monitors = await api_instance.list_monitors()
|
|
171
|
+
print(monitors)
|
|
172
|
+
|
|
173
|
+
asyncio.run(main())
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Threaded API Client
|
|
177
|
+
|
|
178
|
+
For concurrent operations:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from datadog_api_client import Configuration, ThreadedApiClient
|
|
182
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
183
|
+
|
|
184
|
+
configuration = Configuration()
|
|
185
|
+
|
|
186
|
+
with ThreadedApiClient(configuration) as api_client:
|
|
187
|
+
api_instance = DashboardsApi(api_client)
|
|
188
|
+
result = api_instance.list_dashboards()
|
|
189
|
+
dashboards = result.get()
|
|
190
|
+
print(dashboards)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Core API Surfaces
|
|
194
|
+
|
|
195
|
+
### Metrics API
|
|
196
|
+
|
|
197
|
+
#### Submit Metrics (v1)
|
|
198
|
+
|
|
199
|
+
Basic metric submission:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
from datadog_api_client import ApiClient, Configuration
|
|
203
|
+
from datadog_api_client.v1.api.metrics_api import MetricsApi
|
|
204
|
+
from datadog_api_client.v1.model.metrics_payload import MetricsPayload
|
|
205
|
+
from datadog_api_client.v1.model.series import Series
|
|
206
|
+
import time
|
|
207
|
+
|
|
208
|
+
configuration = Configuration()
|
|
209
|
+
|
|
210
|
+
with ApiClient(configuration) as api_client:
|
|
211
|
+
api_instance = MetricsApi(api_client)
|
|
212
|
+
|
|
213
|
+
body = MetricsPayload(
|
|
214
|
+
series=[
|
|
215
|
+
Series(
|
|
216
|
+
metric="system.load.1",
|
|
217
|
+
type="gauge",
|
|
218
|
+
points=[[int(time.time()), 0.7]],
|
|
219
|
+
host="test.example.com",
|
|
220
|
+
tags=["environment:test", "version:1.0"]
|
|
221
|
+
)
|
|
222
|
+
]
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
response = api_instance.submit_metrics(body=body)
|
|
226
|
+
print("Metrics submitted successfully")
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Advanced metric submission with multiple series:
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
from datadog_api_client import ApiClient, Configuration
|
|
233
|
+
from datadog_api_client.v1.api.metrics_api import MetricsApi
|
|
234
|
+
from datadog_api_client.v1.model.metrics_payload import MetricsPayload
|
|
235
|
+
from datadog_api_client.v1.model.series import Series
|
|
236
|
+
import time
|
|
237
|
+
|
|
238
|
+
configuration = Configuration()
|
|
239
|
+
|
|
240
|
+
with ApiClient(configuration) as api_client:
|
|
241
|
+
api_instance = MetricsApi(api_client)
|
|
242
|
+
|
|
243
|
+
now = int(time.time())
|
|
244
|
+
|
|
245
|
+
body = MetricsPayload(
|
|
246
|
+
series=[
|
|
247
|
+
Series(
|
|
248
|
+
metric="custom.app.requests",
|
|
249
|
+
type="count",
|
|
250
|
+
points=[[now, 100]],
|
|
251
|
+
interval=60,
|
|
252
|
+
host="app-server-1",
|
|
253
|
+
tags=["service:api", "env:production"]
|
|
254
|
+
),
|
|
255
|
+
Series(
|
|
256
|
+
metric="custom.app.latency",
|
|
257
|
+
type="gauge",
|
|
258
|
+
points=[[now, 45.2]],
|
|
259
|
+
host="app-server-1",
|
|
260
|
+
tags=["service:api", "env:production"]
|
|
261
|
+
),
|
|
262
|
+
Series(
|
|
263
|
+
metric="custom.app.errors",
|
|
264
|
+
type="count",
|
|
265
|
+
points=[[now, 2]],
|
|
266
|
+
host="app-server-1",
|
|
267
|
+
tags=["service:api", "env:production", "error_type:timeout"]
|
|
268
|
+
)
|
|
269
|
+
]
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
response = api_instance.submit_metrics(body=body)
|
|
273
|
+
print("Multiple metrics submitted")
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
#### Submit Metrics (v2)
|
|
277
|
+
|
|
278
|
+
v2 API with compression support:
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
from datadog_api_client import ApiClient, Configuration
|
|
282
|
+
from datadog_api_client.v2.api.metrics_api import MetricsApi
|
|
283
|
+
from datadog_api_client.v2.model.metric_payload import MetricPayload
|
|
284
|
+
from datadog_api_client.v2.model.metric_series import MetricSeries
|
|
285
|
+
from datadog_api_client.v2.model.metric_point import MetricPoint
|
|
286
|
+
from datadog_api_client.v2.model.metric_resource import MetricResource
|
|
287
|
+
import time
|
|
288
|
+
|
|
289
|
+
configuration = Configuration()
|
|
290
|
+
|
|
291
|
+
with ApiClient(configuration) as api_client:
|
|
292
|
+
api_instance = MetricsApi(api_client)
|
|
293
|
+
|
|
294
|
+
body = MetricPayload(
|
|
295
|
+
series=[
|
|
296
|
+
MetricSeries(
|
|
297
|
+
metric="system.load.1",
|
|
298
|
+
type=0, # gauge
|
|
299
|
+
points=[
|
|
300
|
+
MetricPoint(
|
|
301
|
+
timestamp=int(time.time()),
|
|
302
|
+
value=0.7
|
|
303
|
+
)
|
|
304
|
+
],
|
|
305
|
+
resources=[
|
|
306
|
+
MetricResource(
|
|
307
|
+
name="host",
|
|
308
|
+
type="host"
|
|
309
|
+
)
|
|
310
|
+
],
|
|
311
|
+
tags=["environment:production"]
|
|
312
|
+
)
|
|
313
|
+
]
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
response = api_instance.submit_metrics(body=body)
|
|
317
|
+
print("Metrics submitted with v2 API")
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
#### Query Metrics
|
|
321
|
+
|
|
322
|
+
Query timeseries data:
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
from datadog_api_client import ApiClient, Configuration
|
|
326
|
+
from datadog_api_client.v1.api.metrics_api import MetricsApi
|
|
327
|
+
import time
|
|
328
|
+
|
|
329
|
+
configuration = Configuration()
|
|
330
|
+
|
|
331
|
+
with ApiClient(configuration) as api_client:
|
|
332
|
+
api_instance = MetricsApi(api_client)
|
|
333
|
+
|
|
334
|
+
from_time = int(time.time()) - 3600 # 1 hour ago
|
|
335
|
+
to_time = int(time.time())
|
|
336
|
+
|
|
337
|
+
response = api_instance.query_metrics(
|
|
338
|
+
_from=from_time,
|
|
339
|
+
to=to_time,
|
|
340
|
+
query="avg:system.cpu.user{*}"
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
print("Query results:", response)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Advanced query with aggregation:
|
|
347
|
+
|
|
348
|
+
```python
|
|
349
|
+
from datadog_api_client import ApiClient, Configuration
|
|
350
|
+
from datadog_api_client.v1.api.metrics_api import MetricsApi
|
|
351
|
+
import time
|
|
352
|
+
|
|
353
|
+
configuration = Configuration()
|
|
354
|
+
|
|
355
|
+
with ApiClient(configuration) as api_client:
|
|
356
|
+
api_instance = MetricsApi(api_client)
|
|
357
|
+
|
|
358
|
+
from_time = int(time.time()) - 86400 # 24 hours ago
|
|
359
|
+
to_time = int(time.time())
|
|
360
|
+
|
|
361
|
+
response = api_instance.query_metrics(
|
|
362
|
+
_from=from_time,
|
|
363
|
+
to=to_time,
|
|
364
|
+
query="sum:custom.app.requests{env:production}.rollup(sum, 3600)"
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
print("Aggregated results:", response)
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
#### List Active Metrics
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
from datadog_api_client import ApiClient, Configuration
|
|
374
|
+
from datadog_api_client.v1.api.metrics_api import MetricsApi
|
|
375
|
+
import time
|
|
376
|
+
|
|
377
|
+
configuration = Configuration()
|
|
378
|
+
|
|
379
|
+
with ApiClient(configuration) as api_client:
|
|
380
|
+
api_instance = MetricsApi(api_client)
|
|
381
|
+
|
|
382
|
+
from_time = int(time.time()) - 3600
|
|
383
|
+
|
|
384
|
+
response = api_instance.list_active_metrics(
|
|
385
|
+
_from=from_time
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
print("Active metrics:", response.metrics)
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Monitors API
|
|
392
|
+
|
|
393
|
+
#### Create Monitor
|
|
394
|
+
|
|
395
|
+
Basic monitor creation:
|
|
396
|
+
|
|
397
|
+
```python
|
|
398
|
+
from datadog_api_client import ApiClient, Configuration
|
|
399
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
400
|
+
from datadog_api_client.v1.model.monitor import Monitor
|
|
401
|
+
from datadog_api_client.v1.model.monitor_type import MonitorType
|
|
402
|
+
from datadog_api_client.v1.model.monitor_options import MonitorOptions
|
|
403
|
+
from datadog_api_client.v1.model.monitor_thresholds import MonitorThresholds
|
|
404
|
+
|
|
405
|
+
configuration = Configuration()
|
|
406
|
+
|
|
407
|
+
with ApiClient(configuration) as api_client:
|
|
408
|
+
api_instance = MonitorsApi(api_client)
|
|
409
|
+
|
|
410
|
+
body = Monitor(
|
|
411
|
+
type=MonitorType.METRIC_ALERT,
|
|
412
|
+
query="avg(last_5m):avg:system.cpu.user{*} > 80",
|
|
413
|
+
name="High CPU Usage",
|
|
414
|
+
message="CPU usage is above 80% @slack-alerts",
|
|
415
|
+
tags=["env:production", "team:platform"],
|
|
416
|
+
options=MonitorOptions(
|
|
417
|
+
thresholds=MonitorThresholds(
|
|
418
|
+
critical=80.0,
|
|
419
|
+
warning=60.0
|
|
420
|
+
),
|
|
421
|
+
notify_no_data=True,
|
|
422
|
+
no_data_timeframe=20,
|
|
423
|
+
notify_audit=False,
|
|
424
|
+
require_full_window=False,
|
|
425
|
+
include_tags=True
|
|
426
|
+
)
|
|
427
|
+
)
|
|
428
|
+
|
|
429
|
+
response = api_instance.create_monitor(body=body)
|
|
430
|
+
print(f"Monitor created: {response.id}")
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
Advanced monitor with composite query:
|
|
434
|
+
|
|
435
|
+
```python
|
|
436
|
+
from datadog_api_client import ApiClient, Configuration
|
|
437
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
438
|
+
from datadog_api_client.v1.model.monitor import Monitor
|
|
439
|
+
from datadog_api_client.v1.model.monitor_type import MonitorType
|
|
440
|
+
from datadog_api_client.v1.model.monitor_options import MonitorOptions
|
|
441
|
+
from datadog_api_client.v1.model.monitor_thresholds import MonitorThresholds
|
|
442
|
+
|
|
443
|
+
configuration = Configuration()
|
|
444
|
+
|
|
445
|
+
with ApiClient(configuration) as api_client:
|
|
446
|
+
api_instance = MonitorsApi(api_client)
|
|
447
|
+
|
|
448
|
+
body = Monitor(
|
|
449
|
+
type=MonitorType.QUERY_ALERT,
|
|
450
|
+
query="avg(last_15m):anomalies(avg:custom.app.latency{env:production}, 'basic', 2) >= 1",
|
|
451
|
+
name="Anomalous Latency Detected",
|
|
452
|
+
message="""Application latency is behaving abnormally.
|
|
453
|
+
|
|
454
|
+
Current value: {{value}}
|
|
455
|
+
Threshold: {{threshold}}
|
|
456
|
+
|
|
457
|
+
@pagerduty-critical @slack-alerts""",
|
|
458
|
+
tags=["service:api", "priority:high"],
|
|
459
|
+
priority=1,
|
|
460
|
+
options=MonitorOptions(
|
|
461
|
+
thresholds=MonitorThresholds(
|
|
462
|
+
critical=1.0,
|
|
463
|
+
critical_recovery=0.0
|
|
464
|
+
),
|
|
465
|
+
notify_no_data=True,
|
|
466
|
+
no_data_timeframe=30,
|
|
467
|
+
evaluation_delay=60,
|
|
468
|
+
new_group_delay=300,
|
|
469
|
+
require_full_window=False,
|
|
470
|
+
notify_audit=True,
|
|
471
|
+
timeout_h=24,
|
|
472
|
+
renotify_interval=60,
|
|
473
|
+
escalation_message="Latency issue still ongoing @oncall"
|
|
474
|
+
)
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
response = api_instance.create_monitor(body=body)
|
|
478
|
+
print(f"Anomaly monitor created: {response.id}")
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
#### List Monitors
|
|
482
|
+
|
|
483
|
+
```python
|
|
484
|
+
from datadog_api_client import ApiClient, Configuration
|
|
485
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
486
|
+
|
|
487
|
+
configuration = Configuration()
|
|
488
|
+
|
|
489
|
+
with ApiClient(configuration) as api_client:
|
|
490
|
+
api_instance = MonitorsApi(api_client)
|
|
491
|
+
|
|
492
|
+
monitors = api_instance.list_monitors(
|
|
493
|
+
tags="env:production",
|
|
494
|
+
monitor_tags="team:platform"
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
for monitor in monitors:
|
|
498
|
+
print(f"ID: {monitor.id}, Name: {monitor.name}")
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
#### Get Monitor
|
|
502
|
+
|
|
503
|
+
```python
|
|
504
|
+
from datadog_api_client import ApiClient, Configuration
|
|
505
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
506
|
+
|
|
507
|
+
configuration = Configuration()
|
|
508
|
+
|
|
509
|
+
with ApiClient(configuration) as api_client:
|
|
510
|
+
api_instance = MonitorsApi(api_client)
|
|
511
|
+
|
|
512
|
+
monitor = api_instance.get_monitor(monitor_id=123456)
|
|
513
|
+
print("Monitor details:", monitor)
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
#### Update Monitor
|
|
517
|
+
|
|
518
|
+
```python
|
|
519
|
+
from datadog_api_client import ApiClient, Configuration
|
|
520
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
521
|
+
from datadog_api_client.v1.model.monitor import Monitor
|
|
522
|
+
from datadog_api_client.v1.model.monitor_options import MonitorOptions
|
|
523
|
+
from datadog_api_client.v1.model.monitor_thresholds import MonitorThresholds
|
|
524
|
+
|
|
525
|
+
configuration = Configuration()
|
|
526
|
+
|
|
527
|
+
with ApiClient(configuration) as api_client:
|
|
528
|
+
api_instance = MonitorsApi(api_client)
|
|
529
|
+
|
|
530
|
+
body = Monitor(
|
|
531
|
+
name="Updated Monitor Name",
|
|
532
|
+
options=MonitorOptions(
|
|
533
|
+
thresholds=MonitorThresholds(
|
|
534
|
+
critical=90.0,
|
|
535
|
+
warning=70.0
|
|
536
|
+
)
|
|
537
|
+
)
|
|
538
|
+
)
|
|
539
|
+
|
|
540
|
+
response = api_instance.update_monitor(
|
|
541
|
+
monitor_id=123456,
|
|
542
|
+
body=body
|
|
543
|
+
)
|
|
544
|
+
print("Monitor updated")
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
#### Delete Monitor
|
|
548
|
+
|
|
549
|
+
```python
|
|
550
|
+
from datadog_api_client import ApiClient, Configuration
|
|
551
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
552
|
+
|
|
553
|
+
configuration = Configuration()
|
|
554
|
+
|
|
555
|
+
with ApiClient(configuration) as api_client:
|
|
556
|
+
api_instance = MonitorsApi(api_client)
|
|
557
|
+
|
|
558
|
+
api_instance.delete_monitor(monitor_id=123456)
|
|
559
|
+
print("Monitor deleted")
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### Events API
|
|
563
|
+
|
|
564
|
+
#### Post Event
|
|
565
|
+
|
|
566
|
+
Basic event submission:
|
|
567
|
+
|
|
568
|
+
```python
|
|
569
|
+
from datadog_api_client import ApiClient, Configuration
|
|
570
|
+
from datadog_api_client.v1.api.events_api import EventsApi
|
|
571
|
+
from datadog_api_client.v1.model.event_create_request import EventCreateRequest
|
|
572
|
+
|
|
573
|
+
configuration = Configuration()
|
|
574
|
+
|
|
575
|
+
with ApiClient(configuration) as api_client:
|
|
576
|
+
api_instance = EventsApi(api_client)
|
|
577
|
+
|
|
578
|
+
body = EventCreateRequest(
|
|
579
|
+
title="Application Deployment",
|
|
580
|
+
text="Version 2.0.0 deployed to production",
|
|
581
|
+
tags=["env:production", "version:2.0.0", "deployment"]
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
response = api_instance.create_event(body=body)
|
|
585
|
+
print(f"Event created: {response.event.id}")
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
Advanced event with priority and alert type:
|
|
589
|
+
|
|
590
|
+
```python
|
|
591
|
+
from datadog_api_client import ApiClient, Configuration
|
|
592
|
+
from datadog_api_client.v1.api.events_api import EventsApi
|
|
593
|
+
from datadog_api_client.v1.model.event_create_request import EventCreateRequest
|
|
594
|
+
from datadog_api_client.v1.model.event_priority import EventPriority
|
|
595
|
+
from datadog_api_client.v1.model.event_alert_type import EventAlertType
|
|
596
|
+
import time
|
|
597
|
+
|
|
598
|
+
configuration = Configuration()
|
|
599
|
+
|
|
600
|
+
with ApiClient(configuration) as api_client:
|
|
601
|
+
api_instance = EventsApi(api_client)
|
|
602
|
+
|
|
603
|
+
body = EventCreateRequest(
|
|
604
|
+
title="Database Migration Completed",
|
|
605
|
+
text="""Database migration to schema version 15 completed successfully.
|
|
606
|
+
|
|
607
|
+
Duration: 45 minutes
|
|
608
|
+
Tables affected: 12
|
|
609
|
+
Records migrated: 1.2M""",
|
|
610
|
+
date_happened=int(time.time()),
|
|
611
|
+
priority=EventPriority.NORMAL,
|
|
612
|
+
tags=["service:database", "env:production", "migration"],
|
|
613
|
+
alert_type=EventAlertType.INFO,
|
|
614
|
+
aggregation_key="db_migration_v15",
|
|
615
|
+
source_type_name="my-app",
|
|
616
|
+
host="db-server-1"
|
|
617
|
+
)
|
|
618
|
+
|
|
619
|
+
response = api_instance.create_event(body=body)
|
|
620
|
+
print("Migration event created")
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
#### List Events
|
|
624
|
+
|
|
625
|
+
```python
|
|
626
|
+
from datadog_api_client import ApiClient, Configuration
|
|
627
|
+
from datadog_api_client.v1.api.events_api import EventsApi
|
|
628
|
+
import time
|
|
629
|
+
|
|
630
|
+
configuration = Configuration()
|
|
631
|
+
|
|
632
|
+
with ApiClient(configuration) as api_client:
|
|
633
|
+
api_instance = EventsApi(api_client)
|
|
634
|
+
|
|
635
|
+
end = int(time.time())
|
|
636
|
+
start = end - 3600 # Last hour
|
|
637
|
+
|
|
638
|
+
response = api_instance.list_events(
|
|
639
|
+
start=start,
|
|
640
|
+
end=end,
|
|
641
|
+
tags="env:production"
|
|
642
|
+
)
|
|
643
|
+
|
|
644
|
+
print(f"Found {len(response.events)} events")
|
|
645
|
+
for event in response.events:
|
|
646
|
+
print(f"{event.title}: {event.text}")
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
#### Get Event
|
|
650
|
+
|
|
651
|
+
```python
|
|
652
|
+
from datadog_api_client import ApiClient, Configuration
|
|
653
|
+
from datadog_api_client.v1.api.events_api import EventsApi
|
|
654
|
+
|
|
655
|
+
configuration = Configuration()
|
|
656
|
+
|
|
657
|
+
with ApiClient(configuration) as api_client:
|
|
658
|
+
api_instance = EventsApi(api_client)
|
|
659
|
+
|
|
660
|
+
response = api_instance.get_event(event_id=1234567890)
|
|
661
|
+
print("Event details:", response.event)
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
### Logs API
|
|
665
|
+
|
|
666
|
+
#### Send Logs (v2)
|
|
667
|
+
|
|
668
|
+
Basic log submission:
|
|
669
|
+
|
|
670
|
+
```python
|
|
671
|
+
from datadog_api_client import ApiClient, Configuration
|
|
672
|
+
from datadog_api_client.v2.api.logs_api import LogsApi
|
|
673
|
+
from datadog_api_client.v2.model.http_log import HTTPLog
|
|
674
|
+
from datadog_api_client.v2.model.http_log_item import HTTPLogItem
|
|
675
|
+
|
|
676
|
+
configuration = Configuration()
|
|
677
|
+
|
|
678
|
+
with ApiClient(configuration) as api_client:
|
|
679
|
+
api_instance = LogsApi(api_client)
|
|
680
|
+
|
|
681
|
+
body = [
|
|
682
|
+
HTTPLogItem(
|
|
683
|
+
ddsource="nodejs",
|
|
684
|
+
ddtags="env:production,service:api",
|
|
685
|
+
hostname="app-server-1",
|
|
686
|
+
message="User login successful",
|
|
687
|
+
service="authentication"
|
|
688
|
+
)
|
|
689
|
+
]
|
|
690
|
+
|
|
691
|
+
response = api_instance.submit_log(body=body)
|
|
692
|
+
print("Log submitted")
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
Advanced log submission with structured data:
|
|
696
|
+
|
|
697
|
+
```python
|
|
698
|
+
from datadog_api_client import ApiClient, Configuration
|
|
699
|
+
from datadog_api_client.v2.api.logs_api import LogsApi
|
|
700
|
+
from datadog_api_client.v2.model.http_log_item import HTTPLogItem
|
|
701
|
+
from datetime import datetime
|
|
702
|
+
|
|
703
|
+
configuration = Configuration()
|
|
704
|
+
|
|
705
|
+
with ApiClient(configuration) as api_client:
|
|
706
|
+
api_instance = LogsApi(api_client)
|
|
707
|
+
|
|
708
|
+
body = [
|
|
709
|
+
HTTPLogItem(
|
|
710
|
+
ddsource="application",
|
|
711
|
+
ddtags="env:production,version:2.0.0",
|
|
712
|
+
hostname="api-server-2",
|
|
713
|
+
message="Payment processed successfully",
|
|
714
|
+
service="payment-gateway",
|
|
715
|
+
status="info",
|
|
716
|
+
_date=datetime.now().isoformat(),
|
|
717
|
+
**{
|
|
718
|
+
"transaction_id": "txn_abc123",
|
|
719
|
+
"amount": 99.99,
|
|
720
|
+
"currency": "USD",
|
|
721
|
+
"user_id": "user_456",
|
|
722
|
+
"payment_method": "credit_card"
|
|
723
|
+
}
|
|
724
|
+
)
|
|
725
|
+
]
|
|
726
|
+
|
|
727
|
+
response = api_instance.submit_log(body=body)
|
|
728
|
+
print("Structured log submitted")
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
#### List Logs
|
|
732
|
+
|
|
733
|
+
```python
|
|
734
|
+
from datadog_api_client import ApiClient, Configuration
|
|
735
|
+
from datadog_api_client.v2.api.logs_api import LogsApi
|
|
736
|
+
from datadog_api_client.v2.model.logs_list_request import LogsListRequest
|
|
737
|
+
from datadog_api_client.v2.model.logs_query_filter import LogsQueryFilter
|
|
738
|
+
from datadog_api_client.v2.model.logs_list_request_page import LogsListRequestPage
|
|
739
|
+
from datadog_api_client.v2.model.logs_sort import LogsSort
|
|
740
|
+
from datetime import datetime, timedelta
|
|
741
|
+
|
|
742
|
+
configuration = Configuration()
|
|
743
|
+
|
|
744
|
+
with ApiClient(configuration) as api_client:
|
|
745
|
+
api_instance = LogsApi(api_client)
|
|
746
|
+
|
|
747
|
+
body = LogsListRequest(
|
|
748
|
+
filter=LogsQueryFilter(
|
|
749
|
+
query="service:api status:error",
|
|
750
|
+
_from=(datetime.now() - timedelta(hours=1)).isoformat(),
|
|
751
|
+
to=datetime.now().isoformat()
|
|
752
|
+
),
|
|
753
|
+
page=LogsListRequestPage(limit=50),
|
|
754
|
+
sort=LogsSort.TIMESTAMP_DESCENDING
|
|
755
|
+
)
|
|
756
|
+
|
|
757
|
+
response = api_instance.list_logs(body=body)
|
|
758
|
+
|
|
759
|
+
print(f"Found {len(response.data)} error logs")
|
|
760
|
+
for log in response.data:
|
|
761
|
+
print(log.attributes.message)
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
### Dashboards API
|
|
765
|
+
|
|
766
|
+
#### Create Dashboard
|
|
767
|
+
|
|
768
|
+
Basic dashboard creation:
|
|
769
|
+
|
|
770
|
+
```python
|
|
771
|
+
from datadog_api_client import ApiClient, Configuration
|
|
772
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
773
|
+
from datadog_api_client.v1.model.dashboard import Dashboard
|
|
774
|
+
from datadog_api_client.v1.model.dashboard_layout_type import DashboardLayoutType
|
|
775
|
+
from datadog_api_client.v1.model.widget import Widget
|
|
776
|
+
from datadog_api_client.v1.model.timeseries_widget_definition import TimeseriesWidgetDefinition
|
|
777
|
+
from datadog_api_client.v1.model.timeseries_widget_request import TimeseriesWidgetRequest
|
|
778
|
+
from datadog_api_client.v1.model.widget_display_type import WidgetDisplayType
|
|
779
|
+
|
|
780
|
+
configuration = Configuration()
|
|
781
|
+
|
|
782
|
+
with ApiClient(configuration) as api_client:
|
|
783
|
+
api_instance = DashboardsApi(api_client)
|
|
784
|
+
|
|
785
|
+
body = Dashboard(
|
|
786
|
+
title="System Metrics Dashboard",
|
|
787
|
+
description="Overview of system performance metrics",
|
|
788
|
+
layout_type=DashboardLayoutType.ORDERED,
|
|
789
|
+
widgets=[
|
|
790
|
+
Widget(
|
|
791
|
+
definition=TimeseriesWidgetDefinition(
|
|
792
|
+
type="timeseries",
|
|
793
|
+
requests=[
|
|
794
|
+
TimeseriesWidgetRequest(
|
|
795
|
+
q="avg:system.cpu.user{*}",
|
|
796
|
+
display_type=WidgetDisplayType.LINE
|
|
797
|
+
)
|
|
798
|
+
],
|
|
799
|
+
title="CPU Usage"
|
|
800
|
+
)
|
|
801
|
+
)
|
|
802
|
+
]
|
|
803
|
+
)
|
|
804
|
+
|
|
805
|
+
response = api_instance.create_dashboard(body=body)
|
|
806
|
+
print(f"Dashboard created: {response.id}")
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
Advanced dashboard with multiple widgets:
|
|
810
|
+
|
|
811
|
+
```python
|
|
812
|
+
from datadog_api_client import ApiClient, Configuration
|
|
813
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
814
|
+
from datadog_api_client.v1.model.dashboard import Dashboard
|
|
815
|
+
from datadog_api_client.v1.model.dashboard_layout_type import DashboardLayoutType
|
|
816
|
+
from datadog_api_client.v1.model.widget import Widget
|
|
817
|
+
from datadog_api_client.v1.model.timeseries_widget_definition import TimeseriesWidgetDefinition
|
|
818
|
+
from datadog_api_client.v1.model.timeseries_widget_request import TimeseriesWidgetRequest
|
|
819
|
+
from datadog_api_client.v1.model.query_value_widget_definition import QueryValueWidgetDefinition
|
|
820
|
+
from datadog_api_client.v1.model.query_value_widget_request import QueryValueWidgetRequest
|
|
821
|
+
from datadog_api_client.v1.model.toplist_widget_definition import ToplistWidgetDefinition
|
|
822
|
+
from datadog_api_client.v1.model.toplist_widget_request import ToplistWidgetRequest
|
|
823
|
+
from datadog_api_client.v1.model.widget_display_type import WidgetDisplayType
|
|
824
|
+
from datadog_api_client.v1.model.dashboard_template_variable import DashboardTemplateVariable
|
|
825
|
+
|
|
826
|
+
configuration = Configuration()
|
|
827
|
+
|
|
828
|
+
with ApiClient(configuration) as api_client:
|
|
829
|
+
api_instance = DashboardsApi(api_client)
|
|
830
|
+
|
|
831
|
+
body = Dashboard(
|
|
832
|
+
title="Application Performance Dashboard",
|
|
833
|
+
description="Production application metrics and monitoring",
|
|
834
|
+
layout_type=DashboardLayoutType.ORDERED,
|
|
835
|
+
widgets=[
|
|
836
|
+
Widget(
|
|
837
|
+
definition=TimeseriesWidgetDefinition(
|
|
838
|
+
type="timeseries",
|
|
839
|
+
requests=[
|
|
840
|
+
TimeseriesWidgetRequest(
|
|
841
|
+
q="avg:custom.app.latency{env:production}",
|
|
842
|
+
display_type=WidgetDisplayType.LINE
|
|
843
|
+
)
|
|
844
|
+
],
|
|
845
|
+
title="API Latency",
|
|
846
|
+
show_legend=True
|
|
847
|
+
)
|
|
848
|
+
),
|
|
849
|
+
Widget(
|
|
850
|
+
definition=QueryValueWidgetDefinition(
|
|
851
|
+
type="query_value",
|
|
852
|
+
requests=[
|
|
853
|
+
QueryValueWidgetRequest(
|
|
854
|
+
q="sum:custom.app.requests{env:production}.as_count()",
|
|
855
|
+
aggregator="sum"
|
|
856
|
+
)
|
|
857
|
+
],
|
|
858
|
+
title="Total Requests",
|
|
859
|
+
autoscale=True,
|
|
860
|
+
precision=0
|
|
861
|
+
)
|
|
862
|
+
),
|
|
863
|
+
Widget(
|
|
864
|
+
definition=ToplistWidgetDefinition(
|
|
865
|
+
type="toplist",
|
|
866
|
+
requests=[
|
|
867
|
+
ToplistWidgetRequest(
|
|
868
|
+
q="top(avg:custom.app.errors{env:production} by {error_type}, 10, 'sum', 'desc')"
|
|
869
|
+
)
|
|
870
|
+
],
|
|
871
|
+
title="Top Errors by Type"
|
|
872
|
+
)
|
|
873
|
+
)
|
|
874
|
+
],
|
|
875
|
+
template_variables=[
|
|
876
|
+
DashboardTemplateVariable(
|
|
877
|
+
name="env",
|
|
878
|
+
default="production",
|
|
879
|
+
prefix="env"
|
|
880
|
+
)
|
|
881
|
+
],
|
|
882
|
+
notify_list=["user@example.com"]
|
|
883
|
+
)
|
|
884
|
+
|
|
885
|
+
response = api_instance.create_dashboard(body=body)
|
|
886
|
+
print(f"Advanced dashboard created: {response.id}")
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
#### List Dashboards
|
|
890
|
+
|
|
891
|
+
```python
|
|
892
|
+
from datadog_api_client import ApiClient, Configuration
|
|
893
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
894
|
+
|
|
895
|
+
configuration = Configuration()
|
|
896
|
+
|
|
897
|
+
with ApiClient(configuration) as api_client:
|
|
898
|
+
api_instance = DashboardsApi(api_client)
|
|
899
|
+
|
|
900
|
+
response = api_instance.list_dashboards()
|
|
901
|
+
|
|
902
|
+
for dashboard in response.dashboards:
|
|
903
|
+
print(f"ID: {dashboard.id}, Title: {dashboard.title}")
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
#### Get Dashboard
|
|
907
|
+
|
|
908
|
+
```python
|
|
909
|
+
from datadog_api_client import ApiClient, Configuration
|
|
910
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
911
|
+
|
|
912
|
+
configuration = Configuration()
|
|
913
|
+
|
|
914
|
+
with ApiClient(configuration) as api_client:
|
|
915
|
+
api_instance = DashboardsApi(api_client)
|
|
916
|
+
|
|
917
|
+
dashboard = api_instance.get_dashboard(dashboard_id="abc-def-ghi")
|
|
918
|
+
print("Dashboard:", dashboard)
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
#### Update Dashboard
|
|
922
|
+
|
|
923
|
+
```python
|
|
924
|
+
from datadog_api_client import ApiClient, Configuration
|
|
925
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
926
|
+
from datadog_api_client.v1.model.dashboard import Dashboard
|
|
927
|
+
from datadog_api_client.v1.model.dashboard_layout_type import DashboardLayoutType
|
|
928
|
+
|
|
929
|
+
configuration = Configuration()
|
|
930
|
+
|
|
931
|
+
with ApiClient(configuration) as api_client:
|
|
932
|
+
api_instance = DashboardsApi(api_client)
|
|
933
|
+
|
|
934
|
+
body = Dashboard(
|
|
935
|
+
title="Updated Dashboard Title",
|
|
936
|
+
description="Updated description",
|
|
937
|
+
layout_type=DashboardLayoutType.ORDERED,
|
|
938
|
+
widgets=[] # Include all widgets
|
|
939
|
+
)
|
|
940
|
+
|
|
941
|
+
response = api_instance.update_dashboard(
|
|
942
|
+
dashboard_id="abc-def-ghi",
|
|
943
|
+
body=body
|
|
944
|
+
)
|
|
945
|
+
print("Dashboard updated")
|
|
946
|
+
```
|
|
947
|
+
|
|
948
|
+
#### Delete Dashboard
|
|
949
|
+
|
|
950
|
+
```python
|
|
951
|
+
from datadog_api_client import ApiClient, Configuration
|
|
952
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
953
|
+
|
|
954
|
+
configuration = Configuration()
|
|
955
|
+
|
|
956
|
+
with ApiClient(configuration) as api_client:
|
|
957
|
+
api_instance = DashboardsApi(api_client)
|
|
958
|
+
|
|
959
|
+
api_instance.delete_dashboard(dashboard_id="abc-def-ghi")
|
|
960
|
+
print("Dashboard deleted")
|
|
961
|
+
```
|
|
962
|
+
|
|
963
|
+
### Hosts API
|
|
964
|
+
|
|
965
|
+
#### List Hosts
|
|
966
|
+
|
|
967
|
+
Basic host listing:
|
|
968
|
+
|
|
969
|
+
```python
|
|
970
|
+
from datadog_api_client import ApiClient, Configuration
|
|
971
|
+
from datadog_api_client.v1.api.hosts_api import HostsApi
|
|
972
|
+
|
|
973
|
+
configuration = Configuration()
|
|
974
|
+
|
|
975
|
+
with ApiClient(configuration) as api_client:
|
|
976
|
+
api_instance = HostsApi(api_client)
|
|
977
|
+
|
|
978
|
+
response = api_instance.list_hosts()
|
|
979
|
+
|
|
980
|
+
print(f"Total hosts: {response.total_matching}")
|
|
981
|
+
for host in response.host_list:
|
|
982
|
+
print(f"Host: {host.name}, Up: {host.up}")
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
Advanced host filtering:
|
|
986
|
+
|
|
987
|
+
```python
|
|
988
|
+
from datadog_api_client import ApiClient, Configuration
|
|
989
|
+
from datadog_api_client.v1.api.hosts_api import HostsApi
|
|
990
|
+
import time
|
|
991
|
+
|
|
992
|
+
configuration = Configuration()
|
|
993
|
+
|
|
994
|
+
with ApiClient(configuration) as api_client:
|
|
995
|
+
api_instance = HostsApi(api_client)
|
|
996
|
+
|
|
997
|
+
response = api_instance.list_hosts(
|
|
998
|
+
filter="env:production",
|
|
999
|
+
sort_field="cpu",
|
|
1000
|
+
sort_dir="desc",
|
|
1001
|
+
start=0,
|
|
1002
|
+
count=100,
|
|
1003
|
+
_from=int(time.time()) - 3600
|
|
1004
|
+
)
|
|
1005
|
+
|
|
1006
|
+
print("Production hosts sorted by CPU:")
|
|
1007
|
+
for host in response.host_list:
|
|
1008
|
+
print(f"{host.name}: CPU {host.metrics.cpu}%")
|
|
1009
|
+
```
|
|
1010
|
+
|
|
1011
|
+
#### Get Host Totals
|
|
1012
|
+
|
|
1013
|
+
```python
|
|
1014
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1015
|
+
from datadog_api_client.v1.api.hosts_api import HostsApi
|
|
1016
|
+
import time
|
|
1017
|
+
|
|
1018
|
+
configuration = Configuration()
|
|
1019
|
+
|
|
1020
|
+
with ApiClient(configuration) as api_client:
|
|
1021
|
+
api_instance = HostsApi(api_client)
|
|
1022
|
+
|
|
1023
|
+
response = api_instance.get_host_totals(
|
|
1024
|
+
_from=int(time.time()) - 3600
|
|
1025
|
+
)
|
|
1026
|
+
|
|
1027
|
+
print(f"Total up hosts: {response.total_up}")
|
|
1028
|
+
print(f"Total active hosts: {response.total_active}")
|
|
1029
|
+
```
|
|
1030
|
+
|
|
1031
|
+
### Tags API
|
|
1032
|
+
|
|
1033
|
+
#### Get Host Tags
|
|
1034
|
+
|
|
1035
|
+
```python
|
|
1036
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1037
|
+
from datadog_api_client.v1.api.tags_api import TagsApi
|
|
1038
|
+
|
|
1039
|
+
configuration = Configuration()
|
|
1040
|
+
|
|
1041
|
+
with ApiClient(configuration) as api_client:
|
|
1042
|
+
api_instance = TagsApi(api_client)
|
|
1043
|
+
|
|
1044
|
+
response = api_instance.get_host_tags(host_name="app-server-1")
|
|
1045
|
+
print("Tags for host:", response.tags)
|
|
1046
|
+
```
|
|
1047
|
+
|
|
1048
|
+
#### Update Host Tags
|
|
1049
|
+
|
|
1050
|
+
```python
|
|
1051
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1052
|
+
from datadog_api_client.v1.api.tags_api import TagsApi
|
|
1053
|
+
from datadog_api_client.v1.model.host_tags import HostTags
|
|
1054
|
+
|
|
1055
|
+
configuration = Configuration()
|
|
1056
|
+
|
|
1057
|
+
with ApiClient(configuration) as api_client:
|
|
1058
|
+
api_instance = TagsApi(api_client)
|
|
1059
|
+
|
|
1060
|
+
body = HostTags(
|
|
1061
|
+
tags=[
|
|
1062
|
+
"env:production",
|
|
1063
|
+
"service:api",
|
|
1064
|
+
"version:2.0.0",
|
|
1065
|
+
"team:platform"
|
|
1066
|
+
]
|
|
1067
|
+
)
|
|
1068
|
+
|
|
1069
|
+
response = api_instance.update_host_tags(
|
|
1070
|
+
host_name="app-server-1",
|
|
1071
|
+
body=body
|
|
1072
|
+
)
|
|
1073
|
+
print("Host tags updated")
|
|
1074
|
+
```
|
|
1075
|
+
|
|
1076
|
+
#### Create Host Tags
|
|
1077
|
+
|
|
1078
|
+
```python
|
|
1079
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1080
|
+
from datadog_api_client.v1.api.tags_api import TagsApi
|
|
1081
|
+
from datadog_api_client.v1.model.host_tags import HostTags
|
|
1082
|
+
|
|
1083
|
+
configuration = Configuration()
|
|
1084
|
+
|
|
1085
|
+
with ApiClient(configuration) as api_client:
|
|
1086
|
+
api_instance = TagsApi(api_client)
|
|
1087
|
+
|
|
1088
|
+
body = HostTags(
|
|
1089
|
+
tags=["env:staging", "service:api"]
|
|
1090
|
+
)
|
|
1091
|
+
|
|
1092
|
+
response = api_instance.create_host_tags(
|
|
1093
|
+
host_name="app-server-2",
|
|
1094
|
+
body=body
|
|
1095
|
+
)
|
|
1096
|
+
print("Tags created for new host")
|
|
1097
|
+
```
|
|
1098
|
+
|
|
1099
|
+
#### Delete Host Tags
|
|
1100
|
+
|
|
1101
|
+
```python
|
|
1102
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1103
|
+
from datadog_api_client.v1.api.tags_api import TagsApi
|
|
1104
|
+
|
|
1105
|
+
configuration = Configuration()
|
|
1106
|
+
|
|
1107
|
+
with ApiClient(configuration) as api_client:
|
|
1108
|
+
api_instance = TagsApi(api_client)
|
|
1109
|
+
|
|
1110
|
+
api_instance.delete_host_tags(host_name="app-server-1")
|
|
1111
|
+
print("All tags removed from host")
|
|
1112
|
+
```
|
|
1113
|
+
|
|
1114
|
+
### Service Checks API
|
|
1115
|
+
|
|
1116
|
+
#### Submit Service Check
|
|
1117
|
+
|
|
1118
|
+
Basic service check:
|
|
1119
|
+
|
|
1120
|
+
```python
|
|
1121
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1122
|
+
from datadog_api_client.v1.api.service_checks_api import ServiceChecksApi
|
|
1123
|
+
from datadog_api_client.v1.model.service_check import ServiceCheck
|
|
1124
|
+
from datadog_api_client.v1.model.service_check_status import ServiceCheckStatus
|
|
1125
|
+
|
|
1126
|
+
configuration = Configuration()
|
|
1127
|
+
|
|
1128
|
+
with ApiClient(configuration) as api_client:
|
|
1129
|
+
api_instance = ServiceChecksApi(api_client)
|
|
1130
|
+
|
|
1131
|
+
body = [
|
|
1132
|
+
ServiceCheck(
|
|
1133
|
+
check="app.health",
|
|
1134
|
+
host_name="app-server-1",
|
|
1135
|
+
status=ServiceCheckStatus.OK, # OK, WARNING, CRITICAL, UNKNOWN
|
|
1136
|
+
tags=["env:production"]
|
|
1137
|
+
)
|
|
1138
|
+
]
|
|
1139
|
+
|
|
1140
|
+
response = api_instance.submit_service_check(body=body)
|
|
1141
|
+
print("Service check submitted")
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
Advanced service check with message:
|
|
1145
|
+
|
|
1146
|
+
```python
|
|
1147
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1148
|
+
from datadog_api_client.v1.api.service_checks_api import ServiceChecksApi
|
|
1149
|
+
from datadog_api_client.v1.model.service_check import ServiceCheck
|
|
1150
|
+
from datadog_api_client.v1.model.service_check_status import ServiceCheckStatus
|
|
1151
|
+
import time
|
|
1152
|
+
|
|
1153
|
+
configuration = Configuration()
|
|
1154
|
+
|
|
1155
|
+
with ApiClient(configuration) as api_client:
|
|
1156
|
+
api_instance = ServiceChecksApi(api_client)
|
|
1157
|
+
|
|
1158
|
+
body = [
|
|
1159
|
+
ServiceCheck(
|
|
1160
|
+
check="database.connection",
|
|
1161
|
+
host_name="db-server-1",
|
|
1162
|
+
status=ServiceCheckStatus.CRITICAL,
|
|
1163
|
+
timestamp=int(time.time()),
|
|
1164
|
+
message="Database connection failed: timeout after 30s",
|
|
1165
|
+
tags=["env:production", "service:postgres"]
|
|
1166
|
+
)
|
|
1167
|
+
]
|
|
1168
|
+
|
|
1169
|
+
response = api_instance.submit_service_check(body=body)
|
|
1170
|
+
print("Critical service check submitted")
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
### Downtimes API (v2)
|
|
1174
|
+
|
|
1175
|
+
#### Create Downtime
|
|
1176
|
+
|
|
1177
|
+
Basic downtime creation:
|
|
1178
|
+
|
|
1179
|
+
```python
|
|
1180
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1181
|
+
from datadog_api_client.v2.api.downtimes_api import DowntimesApi
|
|
1182
|
+
from datadog_api_client.v2.model.downtime_create_request import DowntimeCreateRequest
|
|
1183
|
+
from datadog_api_client.v2.model.downtime_create_request_data import DowntimeCreateRequestData
|
|
1184
|
+
from datadog_api_client.v2.model.downtime_create_request_attributes import DowntimeCreateRequestAttributes
|
|
1185
|
+
from datadog_api_client.v2.model.downtime_schedule_create_request import DowntimeScheduleCreateRequest
|
|
1186
|
+
from datetime import datetime, timedelta
|
|
1187
|
+
|
|
1188
|
+
configuration = Configuration()
|
|
1189
|
+
|
|
1190
|
+
with ApiClient(configuration) as api_client:
|
|
1191
|
+
api_instance = DowntimesApi(api_client)
|
|
1192
|
+
|
|
1193
|
+
body = DowntimeCreateRequest(
|
|
1194
|
+
data=DowntimeCreateRequestData(
|
|
1195
|
+
type="downtime",
|
|
1196
|
+
attributes=DowntimeCreateRequestAttributes(
|
|
1197
|
+
scope="env:staging",
|
|
1198
|
+
message="Planned maintenance window",
|
|
1199
|
+
schedule=DowntimeScheduleCreateRequest(
|
|
1200
|
+
start=(datetime.now() + timedelta(hours=1)).isoformat(),
|
|
1201
|
+
end=(datetime.now() + timedelta(hours=2)).isoformat()
|
|
1202
|
+
)
|
|
1203
|
+
)
|
|
1204
|
+
)
|
|
1205
|
+
)
|
|
1206
|
+
|
|
1207
|
+
response = api_instance.create_downtime(body=body)
|
|
1208
|
+
print(f"Downtime created: {response.data.id}")
|
|
1209
|
+
```
|
|
1210
|
+
|
|
1211
|
+
Advanced recurring downtime:
|
|
1212
|
+
|
|
1213
|
+
```python
|
|
1214
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1215
|
+
from datadog_api_client.v2.api.downtimes_api import DowntimesApi
|
|
1216
|
+
from datadog_api_client.v2.model.downtime_create_request import DowntimeCreateRequest
|
|
1217
|
+
from datadog_api_client.v2.model.downtime_create_request_data import DowntimeCreateRequestData
|
|
1218
|
+
from datadog_api_client.v2.model.downtime_create_request_attributes import DowntimeCreateRequestAttributes
|
|
1219
|
+
from datadog_api_client.v2.model.downtime_schedule_create_request import DowntimeScheduleCreateRequest
|
|
1220
|
+
from datadog_api_client.v2.model.downtime_schedule_recurrence_create_update_request import DowntimeScheduleRecurrenceCreateUpdateRequest
|
|
1221
|
+
from datadog_api_client.v2.model.downtime_monitor_identifier import DowntimeMonitorIdentifier
|
|
1222
|
+
from datetime import datetime
|
|
1223
|
+
|
|
1224
|
+
configuration = Configuration()
|
|
1225
|
+
|
|
1226
|
+
with ApiClient(configuration) as api_client:
|
|
1227
|
+
api_instance = DowntimesApi(api_client)
|
|
1228
|
+
|
|
1229
|
+
body = DowntimeCreateRequest(
|
|
1230
|
+
data=DowntimeCreateRequestData(
|
|
1231
|
+
type="downtime",
|
|
1232
|
+
attributes=DowntimeCreateRequestAttributes(
|
|
1233
|
+
scope="host:app-server-*",
|
|
1234
|
+
message="Weekly maintenance window every Sunday",
|
|
1235
|
+
monitor_identifier=DowntimeMonitorIdentifier(
|
|
1236
|
+
monitor_tags=["maintenance:auto"]
|
|
1237
|
+
),
|
|
1238
|
+
schedule=DowntimeScheduleCreateRequest(
|
|
1239
|
+
start=datetime.now().isoformat(),
|
|
1240
|
+
recurrence=DowntimeScheduleRecurrenceCreateUpdateRequest(
|
|
1241
|
+
type="weeks",
|
|
1242
|
+
period=1,
|
|
1243
|
+
week_days=["Sun"]
|
|
1244
|
+
),
|
|
1245
|
+
timezone="America/New_York"
|
|
1246
|
+
),
|
|
1247
|
+
notify_end_states=["alert", "warn"],
|
|
1248
|
+
notify_end_types=["expired", "canceled"]
|
|
1249
|
+
)
|
|
1250
|
+
)
|
|
1251
|
+
)
|
|
1252
|
+
|
|
1253
|
+
response = api_instance.create_downtime(body=body)
|
|
1254
|
+
print("Recurring downtime created")
|
|
1255
|
+
```
|
|
1256
|
+
|
|
1257
|
+
#### List Downtimes
|
|
1258
|
+
|
|
1259
|
+
```python
|
|
1260
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1261
|
+
from datadog_api_client.v2.api.downtimes_api import DowntimesApi
|
|
1262
|
+
|
|
1263
|
+
configuration = Configuration()
|
|
1264
|
+
|
|
1265
|
+
with ApiClient(configuration) as api_client:
|
|
1266
|
+
api_instance = DowntimesApi(api_client)
|
|
1267
|
+
|
|
1268
|
+
response = api_instance.list_downtimes()
|
|
1269
|
+
|
|
1270
|
+
for downtime in response.data:
|
|
1271
|
+
print(f"ID: {downtime.id}, Scope: {downtime.attributes.scope}")
|
|
1272
|
+
```
|
|
1273
|
+
|
|
1274
|
+
#### Cancel Downtime
|
|
1275
|
+
|
|
1276
|
+
```python
|
|
1277
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1278
|
+
from datadog_api_client.v2.api.downtimes_api import DowntimesApi
|
|
1279
|
+
|
|
1280
|
+
configuration = Configuration()
|
|
1281
|
+
|
|
1282
|
+
with ApiClient(configuration) as api_client:
|
|
1283
|
+
api_instance = DowntimesApi(api_client)
|
|
1284
|
+
|
|
1285
|
+
api_instance.cancel_downtime(downtime_id="downtime-id-here")
|
|
1286
|
+
print("Downtime cancelled")
|
|
1287
|
+
```
|
|
1288
|
+
|
|
1289
|
+
### Incidents API (v2)
|
|
1290
|
+
|
|
1291
|
+
#### Create Incident
|
|
1292
|
+
|
|
1293
|
+
```python
|
|
1294
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1295
|
+
from datadog_api_client.v2.api.incidents_api import IncidentsApi
|
|
1296
|
+
from datadog_api_client.v2.model.incident_create_request import IncidentCreateRequest
|
|
1297
|
+
from datadog_api_client.v2.model.incident_create_data import IncidentCreateData
|
|
1298
|
+
from datadog_api_client.v2.model.incident_create_attributes import IncidentCreateAttributes
|
|
1299
|
+
from datadog_api_client.v2.model.incident_field_attributes import IncidentFieldAttributes
|
|
1300
|
+
|
|
1301
|
+
configuration = Configuration()
|
|
1302
|
+
configuration.unstable_operations["create_incident"] = True
|
|
1303
|
+
|
|
1304
|
+
with ApiClient(configuration) as api_client:
|
|
1305
|
+
api_instance = IncidentsApi(api_client)
|
|
1306
|
+
|
|
1307
|
+
body = IncidentCreateRequest(
|
|
1308
|
+
data=IncidentCreateData(
|
|
1309
|
+
type="incidents",
|
|
1310
|
+
attributes=IncidentCreateAttributes(
|
|
1311
|
+
title="Production API Outage",
|
|
1312
|
+
customer_impacted=True,
|
|
1313
|
+
fields={
|
|
1314
|
+
"severity": IncidentFieldAttributes(
|
|
1315
|
+
type="dropdown",
|
|
1316
|
+
value="SEV-1"
|
|
1317
|
+
),
|
|
1318
|
+
"state": IncidentFieldAttributes(
|
|
1319
|
+
type="dropdown",
|
|
1320
|
+
value="active"
|
|
1321
|
+
)
|
|
1322
|
+
}
|
|
1323
|
+
)
|
|
1324
|
+
)
|
|
1325
|
+
)
|
|
1326
|
+
|
|
1327
|
+
response = api_instance.create_incident(body=body)
|
|
1328
|
+
print(f"Incident created: {response.data.id}")
|
|
1329
|
+
```
|
|
1330
|
+
|
|
1331
|
+
#### List Incidents
|
|
1332
|
+
|
|
1333
|
+
```python
|
|
1334
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1335
|
+
from datadog_api_client.v2.api.incidents_api import IncidentsApi
|
|
1336
|
+
|
|
1337
|
+
configuration = Configuration()
|
|
1338
|
+
configuration.unstable_operations["list_incidents"] = True
|
|
1339
|
+
|
|
1340
|
+
with ApiClient(configuration) as api_client:
|
|
1341
|
+
api_instance = IncidentsApi(api_client)
|
|
1342
|
+
|
|
1343
|
+
response = api_instance.list_incidents()
|
|
1344
|
+
|
|
1345
|
+
for incident in response.data:
|
|
1346
|
+
print(f"{incident.id}: {incident.attributes.title}")
|
|
1347
|
+
```
|
|
1348
|
+
|
|
1349
|
+
### SLOs API (Service Level Objectives)
|
|
1350
|
+
|
|
1351
|
+
#### Create SLO
|
|
1352
|
+
|
|
1353
|
+
```python
|
|
1354
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1355
|
+
from datadog_api_client.v1.api.service_level_objectives_api import ServiceLevelObjectivesApi
|
|
1356
|
+
from datadog_api_client.v1.model.service_level_objective_request import ServiceLevelObjectiveRequest
|
|
1357
|
+
from datadog_api_client.v1.model.slo_type import SLOType
|
|
1358
|
+
from datadog_api_client.v1.model.slo_threshold import SLOThreshold
|
|
1359
|
+
from datadog_api_client.v1.model.slo_timeframe import SLOTimeframe
|
|
1360
|
+
|
|
1361
|
+
configuration = Configuration()
|
|
1362
|
+
|
|
1363
|
+
with ApiClient(configuration) as api_client:
|
|
1364
|
+
api_instance = ServiceLevelObjectivesApi(api_client)
|
|
1365
|
+
|
|
1366
|
+
body = ServiceLevelObjectiveRequest(
|
|
1367
|
+
type=SLOType.METRIC,
|
|
1368
|
+
name="API Availability SLO",
|
|
1369
|
+
description="99.9% availability for production API",
|
|
1370
|
+
thresholds=[
|
|
1371
|
+
SLOThreshold(
|
|
1372
|
+
target=99.9,
|
|
1373
|
+
target_display="99.9",
|
|
1374
|
+
timeframe=SLOTimeframe.THIRTY_DAYS,
|
|
1375
|
+
warning=99.95
|
|
1376
|
+
)
|
|
1377
|
+
],
|
|
1378
|
+
query={
|
|
1379
|
+
"numerator": "sum:api.requests{status:ok}.as_count()",
|
|
1380
|
+
"denominator": "sum:api.requests{*}.as_count()"
|
|
1381
|
+
},
|
|
1382
|
+
tags=["service:api", "env:production"]
|
|
1383
|
+
)
|
|
1384
|
+
|
|
1385
|
+
response = api_instance.create_slo(body=body)
|
|
1386
|
+
print(f"SLO created: {response.data[0].id}")
|
|
1387
|
+
```
|
|
1388
|
+
|
|
1389
|
+
#### List SLOs
|
|
1390
|
+
|
|
1391
|
+
```python
|
|
1392
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1393
|
+
from datadog_api_client.v1.api.service_level_objectives_api import ServiceLevelObjectivesApi
|
|
1394
|
+
|
|
1395
|
+
configuration = Configuration()
|
|
1396
|
+
|
|
1397
|
+
with ApiClient(configuration) as api_client:
|
|
1398
|
+
api_instance = ServiceLevelObjectivesApi(api_client)
|
|
1399
|
+
|
|
1400
|
+
response = api_instance.list_slos(tags="service:api")
|
|
1401
|
+
|
|
1402
|
+
for slo in response.data:
|
|
1403
|
+
print(f"{slo.name}: {slo.thresholds[0].target}%")
|
|
1404
|
+
```
|
|
1405
|
+
|
|
1406
|
+
### Users API
|
|
1407
|
+
|
|
1408
|
+
#### List Users
|
|
1409
|
+
|
|
1410
|
+
```python
|
|
1411
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1412
|
+
from datadog_api_client.v2.api.users_api import UsersApi
|
|
1413
|
+
|
|
1414
|
+
configuration = Configuration()
|
|
1415
|
+
|
|
1416
|
+
with ApiClient(configuration) as api_client:
|
|
1417
|
+
api_instance = UsersApi(api_client)
|
|
1418
|
+
|
|
1419
|
+
response = api_instance.list_users()
|
|
1420
|
+
|
|
1421
|
+
for user in response.data:
|
|
1422
|
+
print(f"{user.attributes.name}: {user.attributes.email}")
|
|
1423
|
+
```
|
|
1424
|
+
|
|
1425
|
+
#### Create User
|
|
1426
|
+
|
|
1427
|
+
```python
|
|
1428
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1429
|
+
from datadog_api_client.v2.api.users_api import UsersApi
|
|
1430
|
+
from datadog_api_client.v2.model.user_create_request import UserCreateRequest
|
|
1431
|
+
from datadog_api_client.v2.model.user_create_data import UserCreateData
|
|
1432
|
+
from datadog_api_client.v2.model.user_create_attributes import UserCreateAttributes
|
|
1433
|
+
|
|
1434
|
+
configuration = Configuration()
|
|
1435
|
+
|
|
1436
|
+
with ApiClient(configuration) as api_client:
|
|
1437
|
+
api_instance = UsersApi(api_client)
|
|
1438
|
+
|
|
1439
|
+
body = UserCreateRequest(
|
|
1440
|
+
data=UserCreateData(
|
|
1441
|
+
type="users",
|
|
1442
|
+
attributes=UserCreateAttributes(
|
|
1443
|
+
name="John Doe",
|
|
1444
|
+
email="john.doe@example.com"
|
|
1445
|
+
)
|
|
1446
|
+
)
|
|
1447
|
+
)
|
|
1448
|
+
|
|
1449
|
+
response = api_instance.create_user(body=body)
|
|
1450
|
+
print(f"User created: {response.data.id}")
|
|
1451
|
+
```
|
|
1452
|
+
|
|
1453
|
+
## Error Handling
|
|
1454
|
+
|
|
1455
|
+
### Basic Error Handling
|
|
1456
|
+
|
|
1457
|
+
```python
|
|
1458
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1459
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
1460
|
+
from datadog_api_client.exceptions import ApiException
|
|
1461
|
+
|
|
1462
|
+
configuration = Configuration()
|
|
1463
|
+
|
|
1464
|
+
with ApiClient(configuration) as api_client:
|
|
1465
|
+
api_instance = MonitorsApi(api_client)
|
|
1466
|
+
|
|
1467
|
+
try:
|
|
1468
|
+
monitors = api_instance.list_monitors()
|
|
1469
|
+
print("Success:", monitors)
|
|
1470
|
+
except ApiException as e:
|
|
1471
|
+
print(f"API Exception: {e.status} - {e.reason}")
|
|
1472
|
+
print(f"Body: {e.body}")
|
|
1473
|
+
except Exception as e:
|
|
1474
|
+
print(f"Error: {str(e)}")
|
|
1475
|
+
```
|
|
1476
|
+
|
|
1477
|
+
### Advanced Error Handling with Retry
|
|
1478
|
+
|
|
1479
|
+
```python
|
|
1480
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1481
|
+
from datadog_api_client.v1.api.metrics_api import MetricsApi
|
|
1482
|
+
from datadog_api_client.v1.model.metrics_payload import MetricsPayload
|
|
1483
|
+
from datadog_api_client.v1.model.series import Series
|
|
1484
|
+
from datadog_api_client.exceptions import ApiException
|
|
1485
|
+
import time
|
|
1486
|
+
|
|
1487
|
+
configuration = Configuration()
|
|
1488
|
+
|
|
1489
|
+
def submit_metrics_with_retry(max_retries=3):
|
|
1490
|
+
with ApiClient(configuration) as api_client:
|
|
1491
|
+
api_instance = MetricsApi(api_client)
|
|
1492
|
+
|
|
1493
|
+
body = MetricsPayload(
|
|
1494
|
+
series=[
|
|
1495
|
+
Series(
|
|
1496
|
+
metric="custom.metric",
|
|
1497
|
+
points=[[int(time.time()), 100]]
|
|
1498
|
+
)
|
|
1499
|
+
]
|
|
1500
|
+
)
|
|
1501
|
+
|
|
1502
|
+
for attempt in range(max_retries):
|
|
1503
|
+
try:
|
|
1504
|
+
result = api_instance.submit_metrics(body=body)
|
|
1505
|
+
print("Metrics submitted successfully")
|
|
1506
|
+
return result
|
|
1507
|
+
except ApiException as e:
|
|
1508
|
+
if e.status == 429:
|
|
1509
|
+
print(f"Rate limited - retry {attempt + 1}/{max_retries}")
|
|
1510
|
+
time.sleep(2 ** attempt)
|
|
1511
|
+
elif e.status == 403:
|
|
1512
|
+
print("Authentication failed - check API keys")
|
|
1513
|
+
raise
|
|
1514
|
+
elif e.status == 400:
|
|
1515
|
+
print(f"Bad request: {e.body}")
|
|
1516
|
+
raise
|
|
1517
|
+
else:
|
|
1518
|
+
print(f"Unexpected error: {e}")
|
|
1519
|
+
raise
|
|
1520
|
+
|
|
1521
|
+
submit_metrics_with_retry()
|
|
1522
|
+
```
|
|
1523
|
+
|
|
1524
|
+
## Pagination
|
|
1525
|
+
|
|
1526
|
+
### Manual Pagination
|
|
1527
|
+
|
|
1528
|
+
```python
|
|
1529
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1530
|
+
from datadog_api_client.v1.api.hosts_api import HostsApi
|
|
1531
|
+
|
|
1532
|
+
configuration = Configuration()
|
|
1533
|
+
|
|
1534
|
+
def get_all_hosts():
|
|
1535
|
+
with ApiClient(configuration) as api_client:
|
|
1536
|
+
api_instance = HostsApi(api_client)
|
|
1537
|
+
|
|
1538
|
+
all_hosts = []
|
|
1539
|
+
start = 0
|
|
1540
|
+
count = 100
|
|
1541
|
+
has_more = True
|
|
1542
|
+
|
|
1543
|
+
while has_more:
|
|
1544
|
+
response = api_instance.list_hosts(start=start, count=count)
|
|
1545
|
+
|
|
1546
|
+
if response.host_list:
|
|
1547
|
+
all_hosts.extend(response.host_list)
|
|
1548
|
+
|
|
1549
|
+
start += count
|
|
1550
|
+
has_more = len(response.host_list) == count
|
|
1551
|
+
|
|
1552
|
+
return all_hosts
|
|
1553
|
+
|
|
1554
|
+
hosts = get_all_hosts()
|
|
1555
|
+
print(f"Retrieved {len(hosts)} total hosts")
|
|
1556
|
+
```
|
|
1557
|
+
|
|
1558
|
+
### Automatic Pagination with Iterator
|
|
1559
|
+
|
|
1560
|
+
```python
|
|
1561
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1562
|
+
from datadog_api_client.v2.api.incidents_api import IncidentsApi
|
|
1563
|
+
|
|
1564
|
+
configuration = Configuration()
|
|
1565
|
+
configuration.unstable_operations["list_incidents"] = True
|
|
1566
|
+
|
|
1567
|
+
with ApiClient(configuration) as api_client:
|
|
1568
|
+
api_instance = IncidentsApi(api_client)
|
|
1569
|
+
|
|
1570
|
+
# Some endpoints support pagination
|
|
1571
|
+
for incident in api_instance.list_incidents_with_pagination():
|
|
1572
|
+
print(f"Incident: {incident.id} - {incident.attributes.title}")
|
|
1573
|
+
```
|
|
1574
|
+
|
|
1575
|
+
## Async/Await Pattern
|
|
1576
|
+
|
|
1577
|
+
```python
|
|
1578
|
+
import asyncio
|
|
1579
|
+
from datadog_api_client import AsyncApiClient, Configuration
|
|
1580
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
1581
|
+
from datadog_api_client.v1.api.events_api import EventsApi
|
|
1582
|
+
from datadog_api_client.v1.model.monitor import Monitor
|
|
1583
|
+
from datadog_api_client.v1.model.monitor_type import MonitorType
|
|
1584
|
+
from datadog_api_client.v1.model.event_create_request import EventCreateRequest
|
|
1585
|
+
|
|
1586
|
+
async def monitor_workflow():
|
|
1587
|
+
configuration = Configuration()
|
|
1588
|
+
|
|
1589
|
+
async with AsyncApiClient(configuration) as api_client:
|
|
1590
|
+
monitors_api = MonitorsApi(api_client)
|
|
1591
|
+
events_api = EventsApi(api_client)
|
|
1592
|
+
|
|
1593
|
+
try:
|
|
1594
|
+
# Create monitor
|
|
1595
|
+
monitor_body = Monitor(
|
|
1596
|
+
type=MonitorType.METRIC_ALERT,
|
|
1597
|
+
query="avg(last_5m):avg:system.cpu.user{*} > 80",
|
|
1598
|
+
name="High CPU Alert",
|
|
1599
|
+
message="CPU is high @slack-alerts"
|
|
1600
|
+
)
|
|
1601
|
+
|
|
1602
|
+
monitor = await monitors_api.create_monitor(body=monitor_body)
|
|
1603
|
+
print(f"Monitor created: {monitor.id}")
|
|
1604
|
+
|
|
1605
|
+
# Post event about monitor creation
|
|
1606
|
+
event_body = EventCreateRequest(
|
|
1607
|
+
title="Monitor Created",
|
|
1608
|
+
text=f"Created new monitor: {monitor.name}",
|
|
1609
|
+
tags=["automation", "monitoring"]
|
|
1610
|
+
)
|
|
1611
|
+
|
|
1612
|
+
await events_api.create_event(body=event_body)
|
|
1613
|
+
print("Event posted")
|
|
1614
|
+
|
|
1615
|
+
# List all monitors
|
|
1616
|
+
monitors = await monitors_api.list_monitors()
|
|
1617
|
+
print(f"Total monitors: {len(monitors)}")
|
|
1618
|
+
|
|
1619
|
+
except Exception as e:
|
|
1620
|
+
print(f"Workflow failed: {e}")
|
|
1621
|
+
|
|
1622
|
+
asyncio.run(monitor_workflow())
|
|
1623
|
+
```
|
|
1624
|
+
|
|
1625
|
+
## Concurrent Async Operations
|
|
1626
|
+
|
|
1627
|
+
```python
|
|
1628
|
+
import asyncio
|
|
1629
|
+
from datadog_api_client import AsyncApiClient, Configuration
|
|
1630
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
1631
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
1632
|
+
from datadog_api_client.v1.api.hosts_api import HostsApi
|
|
1633
|
+
|
|
1634
|
+
async def fetch_all_data():
|
|
1635
|
+
configuration = Configuration()
|
|
1636
|
+
|
|
1637
|
+
async with AsyncApiClient(configuration) as api_client:
|
|
1638
|
+
monitors_api = MonitorsApi(api_client)
|
|
1639
|
+
dashboards_api = DashboardsApi(api_client)
|
|
1640
|
+
hosts_api = HostsApi(api_client)
|
|
1641
|
+
|
|
1642
|
+
# Run multiple API calls concurrently
|
|
1643
|
+
monitors, dashboards, hosts = await asyncio.gather(
|
|
1644
|
+
monitors_api.list_monitors(),
|
|
1645
|
+
dashboards_api.list_dashboards(),
|
|
1646
|
+
hosts_api.list_hosts()
|
|
1647
|
+
)
|
|
1648
|
+
|
|
1649
|
+
print(f"Monitors: {len(monitors)}")
|
|
1650
|
+
print(f"Dashboards: {len(dashboards.dashboards)}")
|
|
1651
|
+
print(f"Hosts: {len(hosts.host_list)}")
|
|
1652
|
+
|
|
1653
|
+
asyncio.run(fetch_all_data())
|
|
1654
|
+
```
|
|
1655
|
+
|
|
1656
|
+
## Threaded API Client
|
|
1657
|
+
|
|
1658
|
+
```python
|
|
1659
|
+
from datadog_api_client import Configuration, ThreadedApiClient
|
|
1660
|
+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
|
|
1661
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
1662
|
+
|
|
1663
|
+
configuration = Configuration()
|
|
1664
|
+
|
|
1665
|
+
with ThreadedApiClient(configuration) as api_client:
|
|
1666
|
+
dashboards_api = DashboardsApi(api_client)
|
|
1667
|
+
monitors_api = MonitorsApi(api_client)
|
|
1668
|
+
|
|
1669
|
+
# Start both requests concurrently
|
|
1670
|
+
dashboards_future = dashboards_api.list_dashboards()
|
|
1671
|
+
monitors_future = monitors_api.list_monitors()
|
|
1672
|
+
|
|
1673
|
+
# Wait for results
|
|
1674
|
+
dashboards = dashboards_future.get()
|
|
1675
|
+
monitors = monitors_future.get()
|
|
1676
|
+
|
|
1677
|
+
print(f"Dashboards: {len(dashboards.dashboards)}")
|
|
1678
|
+
print(f"Monitors: {len(monitors)}")
|
|
1679
|
+
```
|
|
1680
|
+
|
|
1681
|
+
## Type Hints
|
|
1682
|
+
|
|
1683
|
+
The package includes full type hints for better IDE support:
|
|
1684
|
+
|
|
1685
|
+
```python
|
|
1686
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1687
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
1688
|
+
from datadog_api_client.v1.model.monitor import Monitor
|
|
1689
|
+
from datadog_api_client.v1.model.monitor_type import MonitorType
|
|
1690
|
+
from datadog_api_client.v1.model.series import Series
|
|
1691
|
+
from datadog_api_client.v1.model.event_create_request import EventCreateRequest
|
|
1692
|
+
from datadog_api_client.v1.model.event_priority import EventPriority
|
|
1693
|
+
from datadog_api_client.v1.model.event_alert_type import EventAlertType
|
|
1694
|
+
from typing import List
|
|
1695
|
+
|
|
1696
|
+
configuration: Configuration = Configuration()
|
|
1697
|
+
|
|
1698
|
+
# Monitor type
|
|
1699
|
+
monitor: Monitor = Monitor(
|
|
1700
|
+
type=MonitorType.METRIC_ALERT,
|
|
1701
|
+
query="avg(last_5m):avg:system.cpu.user{*} > 80",
|
|
1702
|
+
name="CPU Alert",
|
|
1703
|
+
message="High CPU usage detected"
|
|
1704
|
+
)
|
|
1705
|
+
|
|
1706
|
+
# Metric series type
|
|
1707
|
+
series: Series = Series(
|
|
1708
|
+
metric="custom.metric",
|
|
1709
|
+
points=[[1234567890, 100]],
|
|
1710
|
+
type="gauge",
|
|
1711
|
+
host="server-1",
|
|
1712
|
+
tags=["env:prod"]
|
|
1713
|
+
)
|
|
1714
|
+
|
|
1715
|
+
# Event type
|
|
1716
|
+
event: EventCreateRequest = EventCreateRequest(
|
|
1717
|
+
title="Deployment",
|
|
1718
|
+
text="Version deployed",
|
|
1719
|
+
date_happened=1234567890,
|
|
1720
|
+
priority=EventPriority.NORMAL,
|
|
1721
|
+
tags=["deployment"],
|
|
1722
|
+
alert_type=EventAlertType.INFO
|
|
1723
|
+
)
|
|
1724
|
+
```
|
|
1725
|
+
|
|
1726
|
+
## Debug Logging
|
|
1727
|
+
|
|
1728
|
+
Enable debug logging to see request/response details:
|
|
1729
|
+
|
|
1730
|
+
```python
|
|
1731
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1732
|
+
import logging
|
|
1733
|
+
|
|
1734
|
+
# Enable debug logging
|
|
1735
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
1736
|
+
|
|
1737
|
+
configuration = Configuration()
|
|
1738
|
+
configuration.debug = True
|
|
1739
|
+
|
|
1740
|
+
with ApiClient(configuration) as api_client:
|
|
1741
|
+
# All API calls will log request and response details
|
|
1742
|
+
pass
|
|
1743
|
+
```
|
|
1744
|
+
|
|
1745
|
+
## Custom Server Configuration
|
|
1746
|
+
|
|
1747
|
+
```python
|
|
1748
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1749
|
+
|
|
1750
|
+
configuration = Configuration()
|
|
1751
|
+
|
|
1752
|
+
# Custom server URL
|
|
1753
|
+
configuration.host = "https://api.datadoghq.com"
|
|
1754
|
+
|
|
1755
|
+
# Or use server variables
|
|
1756
|
+
configuration.server_variables["site"] = "datadoghq.eu"
|
|
1757
|
+
configuration.server_variables["subdomain"] = "app"
|
|
1758
|
+
|
|
1759
|
+
with ApiClient(configuration) as api_client:
|
|
1760
|
+
# Use api_client for API calls
|
|
1761
|
+
pass
|
|
1762
|
+
```
|
|
1763
|
+
|
|
1764
|
+
## Context Manager Best Practices
|
|
1765
|
+
|
|
1766
|
+
Always use context managers to ensure proper resource cleanup:
|
|
1767
|
+
|
|
1768
|
+
```python
|
|
1769
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1770
|
+
from datadog_api_client.v1.api.monitors_api import MonitorsApi
|
|
1771
|
+
|
|
1772
|
+
configuration = Configuration()
|
|
1773
|
+
|
|
1774
|
+
# Good: Using context manager
|
|
1775
|
+
with ApiClient(configuration) as api_client:
|
|
1776
|
+
api_instance = MonitorsApi(api_client)
|
|
1777
|
+
monitors = api_instance.list_monitors()
|
|
1778
|
+
|
|
1779
|
+
# The client is automatically closed when exiting the context
|
|
1780
|
+
```
|
|
1781
|
+
|
|
1782
|
+
## Batch Operations
|
|
1783
|
+
|
|
1784
|
+
Submit multiple operations efficiently:
|
|
1785
|
+
|
|
1786
|
+
```python
|
|
1787
|
+
from datadog_api_client import ApiClient, Configuration
|
|
1788
|
+
from datadog_api_client.v1.api.metrics_api import MetricsApi
|
|
1789
|
+
from datadog_api_client.v1.model.metrics_payload import MetricsPayload
|
|
1790
|
+
from datadog_api_client.v1.model.series import Series
|
|
1791
|
+
import time
|
|
1792
|
+
|
|
1793
|
+
configuration = Configuration()
|
|
1794
|
+
|
|
1795
|
+
with ApiClient(configuration) as api_client:
|
|
1796
|
+
api_instance = MetricsApi(api_client)
|
|
1797
|
+
|
|
1798
|
+
# Batch multiple metrics in one request
|
|
1799
|
+
now = int(time.time())
|
|
1800
|
+
series_list = []
|
|
1801
|
+
|
|
1802
|
+
for i in range(100):
|
|
1803
|
+
series_list.append(
|
|
1804
|
+
Series(
|
|
1805
|
+
metric=f"custom.metric.{i}",
|
|
1806
|
+
points=[[now, i]],
|
|
1807
|
+
type="gauge",
|
|
1808
|
+
tags=["batch:true"]
|
|
1809
|
+
)
|
|
1810
|
+
)
|
|
1811
|
+
|
|
1812
|
+
body = MetricsPayload(series=series_list)
|
|
1813
|
+
response = api_instance.submit_metrics(body=body)
|
|
1814
|
+
print("Batch of 100 metrics submitted")
|
|
1815
|
+
```
|