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,1740 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: monitoring
|
|
3
|
+
description: "Official Datadog API client for JavaScript/TypeScript to submit metrics, manage monitors, and interact with Datadog observability features."
|
|
4
|
+
metadata:
|
|
5
|
+
languages: "javascript"
|
|
6
|
+
versions: "1.46.0"
|
|
7
|
+
updated-on: "2026-03-01"
|
|
8
|
+
source: maintainer
|
|
9
|
+
tags: "datadog,monitoring,metrics,observability,apm"
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Datadog API Client for JavaScript/TypeScript
|
|
13
|
+
|
|
14
|
+
## Golden Rule
|
|
15
|
+
|
|
16
|
+
**ALWAYS use `@datadog/datadog-api-client` version 1.46.0 or later.**
|
|
17
|
+
|
|
18
|
+
This is the official Datadog API client for JavaScript and TypeScript. Do NOT use:
|
|
19
|
+
- `datadog-client` (unofficial/deprecated)
|
|
20
|
+
- `datadog-metrics` (limited functionality, community package)
|
|
21
|
+
- Direct HTTP calls to Datadog API endpoints (use the official client instead)
|
|
22
|
+
|
|
23
|
+
The `@datadog/datadog-api-client` package provides complete access to both v1 and v2 Datadog APIs with full TypeScript support.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### NPM
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @datadog/datadog-api-client
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Yarn
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
yarn add @datadog/datadog-api-client
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Environment Variables
|
|
40
|
+
|
|
41
|
+
Set up your Datadog API credentials as environment variables:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
export DD_API_KEY="your-api-key-here"
|
|
45
|
+
export DD_APP_KEY="your-application-key-here"
|
|
46
|
+
export DD_SITE="datadoghq.com" # Optional: defaults to US site
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For EU region:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
export DD_SITE="datadoghq.eu"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Initialization
|
|
56
|
+
|
|
57
|
+
### Basic Initialization with Environment Variables
|
|
58
|
+
|
|
59
|
+
The client automatically reads `DD_API_KEY` and `DD_APP_KEY` environment variables:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { client, v1, v2 } from '@datadog/datadog-api-client';
|
|
63
|
+
|
|
64
|
+
const configuration = client.createConfiguration();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Manual Authentication
|
|
68
|
+
|
|
69
|
+
Provide credentials explicitly in code:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
73
|
+
|
|
74
|
+
const configurationOpts = {
|
|
75
|
+
authMethods: {
|
|
76
|
+
apiKeyAuth: "your-api-key-here",
|
|
77
|
+
appKeyAuth: "your-application-key-here"
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Regional Configuration
|
|
85
|
+
|
|
86
|
+
Configure for EU or other regions:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { client } from '@datadog/datadog-api-client';
|
|
90
|
+
|
|
91
|
+
const configuration = client.createConfiguration();
|
|
92
|
+
configuration.setServerVariables({
|
|
93
|
+
site: "datadoghq.eu" // EU region
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Available sites:
|
|
98
|
+
- `datadoghq.com` (US1 - default)
|
|
99
|
+
- `datadoghq.eu` (EU1)
|
|
100
|
+
- `us3.datadoghq.com` (US3)
|
|
101
|
+
- `us5.datadoghq.com` (US5)
|
|
102
|
+
- `ap1.datadoghq.com` (AP1)
|
|
103
|
+
- `ddog-gov.com` (US1-FED)
|
|
104
|
+
|
|
105
|
+
### Advanced Configuration Options
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { client } from '@datadog/datadog-api-client';
|
|
109
|
+
|
|
110
|
+
const configurationOpts = {
|
|
111
|
+
authMethods: {
|
|
112
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
113
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
114
|
+
},
|
|
115
|
+
enableRetry: true, // Enable automatic retry on rate limiting
|
|
116
|
+
debug: false, // Enable request/response logging
|
|
117
|
+
maxRetries: 3, // Maximum number of retries
|
|
118
|
+
backoffMultiplier: 2, // Backoff multiplier for retries
|
|
119
|
+
httpConfig: {
|
|
120
|
+
timeout: 30000 // Request timeout in milliseconds
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
125
|
+
configuration.setServerVariables({ site: "datadoghq.com" });
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Enable Unstable Operations
|
|
129
|
+
|
|
130
|
+
Some v2 endpoints are marked as unstable and require explicit enablement:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
134
|
+
|
|
135
|
+
const configuration = client.createConfiguration();
|
|
136
|
+
configuration.unstableOperations["v2.listIncidents"] = true;
|
|
137
|
+
configuration.unstableOperations["v2.createIncident"] = true;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Core API Surfaces
|
|
141
|
+
|
|
142
|
+
### Metrics API
|
|
143
|
+
|
|
144
|
+
#### Submit Metrics (v1)
|
|
145
|
+
|
|
146
|
+
Basic metric submission:
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
150
|
+
|
|
151
|
+
const configuration = client.createConfiguration();
|
|
152
|
+
const apiInstance = new v1.MetricsApi(configuration);
|
|
153
|
+
|
|
154
|
+
const params: v1.MetricsApiSubmitMetricsRequest = {
|
|
155
|
+
body: {
|
|
156
|
+
series: [
|
|
157
|
+
{
|
|
158
|
+
metric: "system.load.1",
|
|
159
|
+
points: [
|
|
160
|
+
[Math.floor(Date.now() / 1000), 0.7]
|
|
161
|
+
],
|
|
162
|
+
type: "gauge",
|
|
163
|
+
host: "test.example.com",
|
|
164
|
+
tags: ["environment:test", "version:1.0"]
|
|
165
|
+
}
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
apiInstance.submitMetrics(params)
|
|
171
|
+
.then((data: v1.IntakePayloadAccepted) => {
|
|
172
|
+
console.log("Metrics submitted successfully");
|
|
173
|
+
})
|
|
174
|
+
.catch((error: any) => console.error(error));
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Advanced metric submission with multiple series:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
181
|
+
|
|
182
|
+
const configuration = client.createConfiguration();
|
|
183
|
+
const apiInstance = new v1.MetricsApi(configuration);
|
|
184
|
+
|
|
185
|
+
const now = Math.floor(Date.now() / 1000);
|
|
186
|
+
|
|
187
|
+
const params: v1.MetricsApiSubmitMetricsRequest = {
|
|
188
|
+
body: {
|
|
189
|
+
series: [
|
|
190
|
+
{
|
|
191
|
+
metric: "custom.app.requests",
|
|
192
|
+
points: [[now, 100]],
|
|
193
|
+
type: "count",
|
|
194
|
+
interval: 60,
|
|
195
|
+
host: "app-server-1",
|
|
196
|
+
tags: ["service:api", "env:production"]
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
metric: "custom.app.latency",
|
|
200
|
+
points: [[now, 45.2]],
|
|
201
|
+
type: "gauge",
|
|
202
|
+
host: "app-server-1",
|
|
203
|
+
tags: ["service:api", "env:production"]
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
metric: "custom.app.errors",
|
|
207
|
+
points: [[now, 2]],
|
|
208
|
+
type: "count",
|
|
209
|
+
host: "app-server-1",
|
|
210
|
+
tags: ["service:api", "env:production", "error_type:timeout"]
|
|
211
|
+
}
|
|
212
|
+
]
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
apiInstance.submitMetrics(params)
|
|
217
|
+
.then((data: v1.IntakePayloadAccepted) => {
|
|
218
|
+
console.log("Multiple metrics submitted");
|
|
219
|
+
})
|
|
220
|
+
.catch((error: any) => console.error(error));
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
#### Submit Metrics (v2)
|
|
224
|
+
|
|
225
|
+
v2 API with compression support:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
229
|
+
import { compressSync } from 'zstd.ts';
|
|
230
|
+
|
|
231
|
+
const configurationOpts = {
|
|
232
|
+
zstdCompressorCallback: (body: string) =>
|
|
233
|
+
compressSync({ input: Buffer.from(body, "utf8") })
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
237
|
+
const apiInstance = new v2.MetricsApi(configuration);
|
|
238
|
+
|
|
239
|
+
const params: v2.MetricsApiSubmitMetricsRequest = {
|
|
240
|
+
body: {
|
|
241
|
+
series: [
|
|
242
|
+
{
|
|
243
|
+
metric: "system.load.1",
|
|
244
|
+
type: 0, // gauge
|
|
245
|
+
points: [
|
|
246
|
+
{
|
|
247
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
248
|
+
value: 0.7
|
|
249
|
+
}
|
|
250
|
+
],
|
|
251
|
+
resources: [
|
|
252
|
+
{
|
|
253
|
+
name: "host",
|
|
254
|
+
type: "host"
|
|
255
|
+
}
|
|
256
|
+
],
|
|
257
|
+
tags: ["environment:production"]
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
},
|
|
261
|
+
contentEncoding: "zstd1"
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
apiInstance.submitMetrics(params)
|
|
265
|
+
.then((data: v2.IntakePayloadAccepted) => {
|
|
266
|
+
console.log("Metrics submitted with compression");
|
|
267
|
+
})
|
|
268
|
+
.catch((error: any) => console.error(error));
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
#### Query Metrics
|
|
272
|
+
|
|
273
|
+
Query timeseries data:
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
277
|
+
|
|
278
|
+
const configuration = client.createConfiguration();
|
|
279
|
+
const apiInstance = new v1.MetricsApi(configuration);
|
|
280
|
+
|
|
281
|
+
const from = Math.floor(Date.now() / 1000) - 3600; // 1 hour ago
|
|
282
|
+
const to = Math.floor(Date.now() / 1000);
|
|
283
|
+
|
|
284
|
+
const params: v1.MetricsApiQueryMetricsRequest = {
|
|
285
|
+
from: from,
|
|
286
|
+
to: to,
|
|
287
|
+
query: "avg:system.cpu.user{*}"
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
apiInstance.queryMetrics(params)
|
|
291
|
+
.then((data: v1.MetricsQueryResponse) => {
|
|
292
|
+
console.log("Query results:", JSON.stringify(data, null, 2));
|
|
293
|
+
})
|
|
294
|
+
.catch((error: any) => console.error(error));
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Advanced query with aggregation:
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
301
|
+
|
|
302
|
+
const configuration = client.createConfiguration();
|
|
303
|
+
const apiInstance = new v1.MetricsApi(configuration);
|
|
304
|
+
|
|
305
|
+
const from = Math.floor(Date.now() / 1000) - 86400; // 24 hours ago
|
|
306
|
+
const to = Math.floor(Date.now() / 1000);
|
|
307
|
+
|
|
308
|
+
const params: v1.MetricsApiQueryMetricsRequest = {
|
|
309
|
+
from: from,
|
|
310
|
+
to: to,
|
|
311
|
+
query: "sum:custom.app.requests{env:production}.rollup(sum, 3600)"
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
apiInstance.queryMetrics(params)
|
|
315
|
+
.then((data: v1.MetricsQueryResponse) => {
|
|
316
|
+
console.log("Aggregated results:", data);
|
|
317
|
+
})
|
|
318
|
+
.catch((error: any) => console.error(error));
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### List Active Metrics
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
325
|
+
|
|
326
|
+
const configuration = client.createConfiguration();
|
|
327
|
+
const apiInstance = new v1.MetricsApi(configuration);
|
|
328
|
+
|
|
329
|
+
const from = Math.floor(Date.now() / 1000) - 3600;
|
|
330
|
+
|
|
331
|
+
const params: v1.MetricsApiListActiveMetricsRequest = {
|
|
332
|
+
from: from
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
apiInstance.listActiveMetrics(params)
|
|
336
|
+
.then((data: v1.MetricsListResponse) => {
|
|
337
|
+
console.log("Active metrics:", data.metrics);
|
|
338
|
+
})
|
|
339
|
+
.catch((error: any) => console.error(error));
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Monitors API
|
|
343
|
+
|
|
344
|
+
#### Create Monitor
|
|
345
|
+
|
|
346
|
+
Basic monitor creation:
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
350
|
+
|
|
351
|
+
const configuration = client.createConfiguration();
|
|
352
|
+
const apiInstance = new v1.MonitorsApi(configuration);
|
|
353
|
+
|
|
354
|
+
const params: v1.MonitorsApiCreateMonitorRequest = {
|
|
355
|
+
body: {
|
|
356
|
+
type: "metric alert",
|
|
357
|
+
query: "avg(last_5m):avg:system.cpu.user{*} > 80",
|
|
358
|
+
name: "High CPU Usage",
|
|
359
|
+
message: "CPU usage is above 80% @slack-alerts",
|
|
360
|
+
tags: ["env:production", "team:platform"],
|
|
361
|
+
options: {
|
|
362
|
+
thresholds: {
|
|
363
|
+
critical: 80,
|
|
364
|
+
warning: 60
|
|
365
|
+
},
|
|
366
|
+
notifyNoData: true,
|
|
367
|
+
noDataTimeframe: 20,
|
|
368
|
+
notifyAudit: false,
|
|
369
|
+
requireFullWindow: false,
|
|
370
|
+
includeTag: true
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
apiInstance.createMonitor(params)
|
|
376
|
+
.then((data: v1.Monitor) => {
|
|
377
|
+
console.log("Monitor created:", data.id);
|
|
378
|
+
})
|
|
379
|
+
.catch((error: any) => console.error(error));
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Advanced monitor with composite query:
|
|
383
|
+
|
|
384
|
+
```typescript
|
|
385
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
386
|
+
|
|
387
|
+
const configuration = client.createConfiguration();
|
|
388
|
+
const apiInstance = new v1.MonitorsApi(configuration);
|
|
389
|
+
|
|
390
|
+
const params: v1.MonitorsApiCreateMonitorRequest = {
|
|
391
|
+
body: {
|
|
392
|
+
type: "query alert",
|
|
393
|
+
query: "avg(last_15m):anomalies(avg:custom.app.latency{env:production}, 'basic', 2) >= 1",
|
|
394
|
+
name: "Anomalous Latency Detected",
|
|
395
|
+
message: `Application latency is behaving abnormally.
|
|
396
|
+
|
|
397
|
+
Current value: {{value}}
|
|
398
|
+
Threshold: {{threshold}}
|
|
399
|
+
|
|
400
|
+
@pagerduty-critical @slack-alerts`,
|
|
401
|
+
tags: ["service:api", "priority:high"],
|
|
402
|
+
priority: 1,
|
|
403
|
+
options: {
|
|
404
|
+
thresholds: {
|
|
405
|
+
critical: 1,
|
|
406
|
+
criticalRecovery: 0
|
|
407
|
+
},
|
|
408
|
+
notifyNoData: true,
|
|
409
|
+
noDataTimeframe: 30,
|
|
410
|
+
evaluationDelay: 60,
|
|
411
|
+
newGroupDelay: 300,
|
|
412
|
+
requireFullWindow: false,
|
|
413
|
+
notifyAudit: true,
|
|
414
|
+
timeoutH: 24,
|
|
415
|
+
renotifyInterval: 60,
|
|
416
|
+
escalationMessage: "Latency issue still ongoing @oncall"
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
apiInstance.createMonitor(params)
|
|
422
|
+
.then((data: v1.Monitor) => {
|
|
423
|
+
console.log("Anomaly monitor created:", data.id);
|
|
424
|
+
})
|
|
425
|
+
.catch((error: any) => console.error(error));
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
#### List Monitors
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
432
|
+
|
|
433
|
+
const configuration = client.createConfiguration();
|
|
434
|
+
const apiInstance = new v1.MonitorsApi(configuration);
|
|
435
|
+
|
|
436
|
+
const params: v1.MonitorsApiListMonitorsRequest = {
|
|
437
|
+
tags: "env:production",
|
|
438
|
+
monitorTags: "team:platform"
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
apiInstance.listMonitors(params)
|
|
442
|
+
.then((data: v1.Monitor[]) => {
|
|
443
|
+
data.forEach(monitor => {
|
|
444
|
+
console.log(`ID: ${monitor.id}, Name: ${monitor.name}`);
|
|
445
|
+
});
|
|
446
|
+
})
|
|
447
|
+
.catch((error: any) => console.error(error));
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
#### Get Monitor
|
|
451
|
+
|
|
452
|
+
```typescript
|
|
453
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
454
|
+
|
|
455
|
+
const configuration = client.createConfiguration();
|
|
456
|
+
const apiInstance = new v1.MonitorsApi(configuration);
|
|
457
|
+
|
|
458
|
+
const params: v1.MonitorsApiGetMonitorRequest = {
|
|
459
|
+
monitorId: 123456
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
apiInstance.getMonitor(params)
|
|
463
|
+
.then((data: v1.Monitor) => {
|
|
464
|
+
console.log("Monitor details:", JSON.stringify(data, null, 2));
|
|
465
|
+
})
|
|
466
|
+
.catch((error: any) => console.error(error));
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
#### Update Monitor
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
473
|
+
|
|
474
|
+
const configuration = client.createConfiguration();
|
|
475
|
+
const apiInstance = new v1.MonitorsApi(configuration);
|
|
476
|
+
|
|
477
|
+
const params: v1.MonitorsApiUpdateMonitorRequest = {
|
|
478
|
+
monitorId: 123456,
|
|
479
|
+
body: {
|
|
480
|
+
name: "Updated Monitor Name",
|
|
481
|
+
options: {
|
|
482
|
+
thresholds: {
|
|
483
|
+
critical: 90,
|
|
484
|
+
warning: 70
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
apiInstance.updateMonitor(params)
|
|
491
|
+
.then((data: v1.Monitor) => {
|
|
492
|
+
console.log("Monitor updated");
|
|
493
|
+
})
|
|
494
|
+
.catch((error: any) => console.error(error));
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
#### Delete Monitor
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
501
|
+
|
|
502
|
+
const configuration = client.createConfiguration();
|
|
503
|
+
const apiInstance = new v1.MonitorsApi(configuration);
|
|
504
|
+
|
|
505
|
+
const params: v1.MonitorsApiDeleteMonitorRequest = {
|
|
506
|
+
monitorId: 123456
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
apiInstance.deleteMonitor(params)
|
|
510
|
+
.then((data: v1.DeletedMonitor) => {
|
|
511
|
+
console.log("Monitor deleted");
|
|
512
|
+
})
|
|
513
|
+
.catch((error: any) => console.error(error));
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### Events API
|
|
517
|
+
|
|
518
|
+
#### Post Event
|
|
519
|
+
|
|
520
|
+
Basic event submission:
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
524
|
+
|
|
525
|
+
const configuration = client.createConfiguration();
|
|
526
|
+
const apiInstance = new v1.EventsApi(configuration);
|
|
527
|
+
|
|
528
|
+
const params: v1.EventsApiCreateEventRequest = {
|
|
529
|
+
body: {
|
|
530
|
+
title: "Application Deployment",
|
|
531
|
+
text: "Version 2.0.0 deployed to production",
|
|
532
|
+
tags: ["env:production", "version:2.0.0", "deployment"]
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
apiInstance.createEvent(params)
|
|
537
|
+
.then((data: v1.EventCreateResponse) => {
|
|
538
|
+
console.log("Event created:", data.event?.id);
|
|
539
|
+
})
|
|
540
|
+
.catch((error: any) => console.error(error));
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
Advanced event with priority and alert type:
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
547
|
+
|
|
548
|
+
const configuration = client.createConfiguration();
|
|
549
|
+
const apiInstance = new v1.EventsApi(configuration);
|
|
550
|
+
|
|
551
|
+
const params: v1.EventsApiCreateEventRequest = {
|
|
552
|
+
body: {
|
|
553
|
+
title: "Database Migration Completed",
|
|
554
|
+
text: `Database migration to schema version 15 completed successfully.
|
|
555
|
+
|
|
556
|
+
Duration: 45 minutes
|
|
557
|
+
Tables affected: 12
|
|
558
|
+
Records migrated: 1.2M`,
|
|
559
|
+
dateHappened: Math.floor(Date.now() / 1000),
|
|
560
|
+
priority: "normal",
|
|
561
|
+
tags: ["service:database", "env:production", "migration"],
|
|
562
|
+
alertType: "info",
|
|
563
|
+
aggregationKey: "db_migration_v15",
|
|
564
|
+
sourceTypeName: "my-app",
|
|
565
|
+
host: "db-server-1"
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
apiInstance.createEvent(params)
|
|
570
|
+
.then((data: v1.EventCreateResponse) => {
|
|
571
|
+
console.log("Migration event created");
|
|
572
|
+
})
|
|
573
|
+
.catch((error: any) => console.error(error));
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
#### List Events
|
|
577
|
+
|
|
578
|
+
```typescript
|
|
579
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
580
|
+
|
|
581
|
+
const configuration = client.createConfiguration();
|
|
582
|
+
const apiInstance = new v1.EventsApi(configuration);
|
|
583
|
+
|
|
584
|
+
const end = Math.floor(Date.now() / 1000);
|
|
585
|
+
const start = end - 3600; // Last hour
|
|
586
|
+
|
|
587
|
+
const params: v1.EventsApiListEventsRequest = {
|
|
588
|
+
start: start,
|
|
589
|
+
end: end,
|
|
590
|
+
tags: "env:production"
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
apiInstance.listEvents(params)
|
|
594
|
+
.then((data: v1.EventListResponse) => {
|
|
595
|
+
console.log(`Found ${data.events?.length} events`);
|
|
596
|
+
data.events?.forEach(event => {
|
|
597
|
+
console.log(`${event.title}: ${event.text}`);
|
|
598
|
+
});
|
|
599
|
+
})
|
|
600
|
+
.catch((error: any) => console.error(error));
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
#### Get Event
|
|
604
|
+
|
|
605
|
+
```typescript
|
|
606
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
607
|
+
|
|
608
|
+
const configuration = client.createConfiguration();
|
|
609
|
+
const apiInstance = new v1.EventsApi(configuration);
|
|
610
|
+
|
|
611
|
+
const params: v1.EventsApiGetEventRequest = {
|
|
612
|
+
eventId: 1234567890
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
apiInstance.getEvent(params)
|
|
616
|
+
.then((data: v1.EventResponse) => {
|
|
617
|
+
console.log("Event details:", JSON.stringify(data.event, null, 2));
|
|
618
|
+
})
|
|
619
|
+
.catch((error: any) => console.error(error));
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### Logs API
|
|
623
|
+
|
|
624
|
+
#### Send Logs (v2)
|
|
625
|
+
|
|
626
|
+
Basic log submission:
|
|
627
|
+
|
|
628
|
+
```typescript
|
|
629
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
630
|
+
|
|
631
|
+
const configuration = client.createConfiguration();
|
|
632
|
+
const apiInstance = new v2.LogsApi(configuration);
|
|
633
|
+
|
|
634
|
+
const params: v2.LogsApiSubmitLogRequest = {
|
|
635
|
+
body: [
|
|
636
|
+
{
|
|
637
|
+
ddsource: "nodejs",
|
|
638
|
+
ddtags: "env:production,service:api",
|
|
639
|
+
hostname: "app-server-1",
|
|
640
|
+
message: "User login successful",
|
|
641
|
+
service: "authentication"
|
|
642
|
+
}
|
|
643
|
+
]
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
apiInstance.submitLog(params)
|
|
647
|
+
.then((data: any) => {
|
|
648
|
+
console.log("Log submitted");
|
|
649
|
+
})
|
|
650
|
+
.catch((error: any) => console.error(error));
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
Advanced log submission with structured data:
|
|
654
|
+
|
|
655
|
+
```typescript
|
|
656
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
657
|
+
|
|
658
|
+
const configuration = client.createConfiguration();
|
|
659
|
+
const apiInstance = new v2.LogsApi(configuration);
|
|
660
|
+
|
|
661
|
+
const params: v2.LogsApiSubmitLogRequest = {
|
|
662
|
+
body: [
|
|
663
|
+
{
|
|
664
|
+
ddsource: "application",
|
|
665
|
+
ddtags: "env:production,version:2.0.0",
|
|
666
|
+
hostname: "api-server-2",
|
|
667
|
+
message: "Payment processed successfully",
|
|
668
|
+
service: "payment-gateway",
|
|
669
|
+
status: "info",
|
|
670
|
+
timestamp: new Date().toISOString(),
|
|
671
|
+
attributes: {
|
|
672
|
+
transaction_id: "txn_abc123",
|
|
673
|
+
amount: 99.99,
|
|
674
|
+
currency: "USD",
|
|
675
|
+
user_id: "user_456",
|
|
676
|
+
payment_method: "credit_card"
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
],
|
|
680
|
+
contentEncoding: "gzip"
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
apiInstance.submitLog(params)
|
|
684
|
+
.then((data: any) => {
|
|
685
|
+
console.log("Structured log submitted");
|
|
686
|
+
})
|
|
687
|
+
.catch((error: any) => console.error(error));
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
#### List Logs
|
|
691
|
+
|
|
692
|
+
```typescript
|
|
693
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
694
|
+
|
|
695
|
+
const configuration = client.createConfiguration();
|
|
696
|
+
const apiInstance = new v2.LogsApi(configuration);
|
|
697
|
+
|
|
698
|
+
const params: v2.LogsApiListLogsRequest = {
|
|
699
|
+
body: {
|
|
700
|
+
filter: {
|
|
701
|
+
query: "service:api status:error",
|
|
702
|
+
from: new Date(Date.now() - 3600000).toISOString(),
|
|
703
|
+
to: new Date().toISOString()
|
|
704
|
+
},
|
|
705
|
+
page: {
|
|
706
|
+
limit: 50
|
|
707
|
+
},
|
|
708
|
+
sort: "-timestamp"
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
apiInstance.listLogs(params)
|
|
713
|
+
.then((data: v2.LogsListResponse) => {
|
|
714
|
+
console.log(`Found ${data.data?.length} error logs`);
|
|
715
|
+
data.data?.forEach(log => {
|
|
716
|
+
console.log(log.attributes?.message);
|
|
717
|
+
});
|
|
718
|
+
})
|
|
719
|
+
.catch((error: any) => console.error(error));
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
### Dashboards API
|
|
723
|
+
|
|
724
|
+
#### Create Dashboard
|
|
725
|
+
|
|
726
|
+
Basic dashboard creation:
|
|
727
|
+
|
|
728
|
+
```typescript
|
|
729
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
730
|
+
|
|
731
|
+
const configuration = client.createConfiguration();
|
|
732
|
+
const apiInstance = new v1.DashboardsApi(configuration);
|
|
733
|
+
|
|
734
|
+
const params: v1.DashboardsApiCreateDashboardRequest = {
|
|
735
|
+
body: {
|
|
736
|
+
title: "System Metrics Dashboard",
|
|
737
|
+
description: "Overview of system performance metrics",
|
|
738
|
+
layoutType: "ordered",
|
|
739
|
+
widgets: [
|
|
740
|
+
{
|
|
741
|
+
definition: {
|
|
742
|
+
type: "timeseries",
|
|
743
|
+
requests: [
|
|
744
|
+
{
|
|
745
|
+
q: "avg:system.cpu.user{*}",
|
|
746
|
+
displayType: "line"
|
|
747
|
+
}
|
|
748
|
+
],
|
|
749
|
+
title: "CPU Usage"
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
]
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
apiInstance.createDashboard(params)
|
|
757
|
+
.then((data: v1.Dashboard) => {
|
|
758
|
+
console.log("Dashboard created:", data.id);
|
|
759
|
+
})
|
|
760
|
+
.catch((error: any) => console.error(error));
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
Advanced dashboard with multiple widgets:
|
|
764
|
+
|
|
765
|
+
```typescript
|
|
766
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
767
|
+
|
|
768
|
+
const configuration = client.createConfiguration();
|
|
769
|
+
const apiInstance = new v1.DashboardsApi(configuration);
|
|
770
|
+
|
|
771
|
+
const params: v1.DashboardsApiCreateDashboardRequest = {
|
|
772
|
+
body: {
|
|
773
|
+
title: "Application Performance Dashboard",
|
|
774
|
+
description: "Production application metrics and monitoring",
|
|
775
|
+
layoutType: "ordered",
|
|
776
|
+
widgets: [
|
|
777
|
+
{
|
|
778
|
+
definition: {
|
|
779
|
+
type: "timeseries",
|
|
780
|
+
requests: [
|
|
781
|
+
{
|
|
782
|
+
q: "avg:custom.app.latency{env:production}",
|
|
783
|
+
displayType: "line",
|
|
784
|
+
style: {
|
|
785
|
+
palette: "dog_classic",
|
|
786
|
+
lineType: "solid",
|
|
787
|
+
lineWidth: "normal"
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
],
|
|
791
|
+
title: "API Latency",
|
|
792
|
+
showLegend: true,
|
|
793
|
+
legendLayout: "auto",
|
|
794
|
+
legendColumns: ["avg", "min", "max", "value", "sum"]
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
definition: {
|
|
799
|
+
type: "query_value",
|
|
800
|
+
requests: [
|
|
801
|
+
{
|
|
802
|
+
q: "sum:custom.app.requests{env:production}.as_count()",
|
|
803
|
+
aggregator: "sum"
|
|
804
|
+
}
|
|
805
|
+
],
|
|
806
|
+
title: "Total Requests",
|
|
807
|
+
autoscale: true,
|
|
808
|
+
precision: 0
|
|
809
|
+
}
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
definition: {
|
|
813
|
+
type: "toplist",
|
|
814
|
+
requests: [
|
|
815
|
+
{
|
|
816
|
+
q: "top(avg:custom.app.errors{env:production} by {error_type}, 10, 'sum', 'desc')"
|
|
817
|
+
}
|
|
818
|
+
],
|
|
819
|
+
title: "Top Errors by Type"
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
],
|
|
823
|
+
templateVariables: [
|
|
824
|
+
{
|
|
825
|
+
name: "env",
|
|
826
|
+
defaultValue: "production",
|
|
827
|
+
prefix: "env"
|
|
828
|
+
}
|
|
829
|
+
],
|
|
830
|
+
notifyList: ["user@example.com"]
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
apiInstance.createDashboard(params)
|
|
835
|
+
.then((data: v1.Dashboard) => {
|
|
836
|
+
console.log("Advanced dashboard created:", data.id);
|
|
837
|
+
})
|
|
838
|
+
.catch((error: any) => console.error(error));
|
|
839
|
+
```
|
|
840
|
+
|
|
841
|
+
#### List Dashboards
|
|
842
|
+
|
|
843
|
+
```typescript
|
|
844
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
845
|
+
|
|
846
|
+
const configuration = client.createConfiguration();
|
|
847
|
+
const apiInstance = new v1.DashboardsApi(configuration);
|
|
848
|
+
|
|
849
|
+
apiInstance.listDashboards()
|
|
850
|
+
.then((data: v1.DashboardSummary) => {
|
|
851
|
+
data.dashboards?.forEach(dashboard => {
|
|
852
|
+
console.log(`ID: ${dashboard.id}, Title: ${dashboard.title}`);
|
|
853
|
+
});
|
|
854
|
+
})
|
|
855
|
+
.catch((error: any) => console.error(error));
|
|
856
|
+
```
|
|
857
|
+
|
|
858
|
+
#### Get Dashboard
|
|
859
|
+
|
|
860
|
+
```typescript
|
|
861
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
862
|
+
|
|
863
|
+
const configuration = client.createConfiguration();
|
|
864
|
+
const apiInstance = new v1.DashboardsApi(configuration);
|
|
865
|
+
|
|
866
|
+
const params: v1.DashboardsApiGetDashboardRequest = {
|
|
867
|
+
dashboardId: "abc-def-ghi"
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
apiInstance.getDashboard(params)
|
|
871
|
+
.then((data: v1.Dashboard) => {
|
|
872
|
+
console.log("Dashboard:", JSON.stringify(data, null, 2));
|
|
873
|
+
})
|
|
874
|
+
.catch((error: any) => console.error(error));
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
#### Update Dashboard
|
|
878
|
+
|
|
879
|
+
```typescript
|
|
880
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
881
|
+
|
|
882
|
+
const configuration = client.createConfiguration();
|
|
883
|
+
const apiInstance = new v1.DashboardsApi(configuration);
|
|
884
|
+
|
|
885
|
+
const params: v1.DashboardsApiUpdateDashboardRequest = {
|
|
886
|
+
dashboardId: "abc-def-ghi",
|
|
887
|
+
body: {
|
|
888
|
+
title: "Updated Dashboard Title",
|
|
889
|
+
description: "Updated description",
|
|
890
|
+
layoutType: "ordered",
|
|
891
|
+
widgets: [] // Include all widgets
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
apiInstance.updateDashboard(params)
|
|
896
|
+
.then((data: v1.Dashboard) => {
|
|
897
|
+
console.log("Dashboard updated");
|
|
898
|
+
})
|
|
899
|
+
.catch((error: any) => console.error(error));
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
#### Delete Dashboard
|
|
903
|
+
|
|
904
|
+
```typescript
|
|
905
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
906
|
+
|
|
907
|
+
const configuration = client.createConfiguration();
|
|
908
|
+
const apiInstance = new v1.DashboardsApi(configuration);
|
|
909
|
+
|
|
910
|
+
const params: v1.DashboardsApiDeleteDashboardRequest = {
|
|
911
|
+
dashboardId: "abc-def-ghi"
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
apiInstance.deleteDashboard(params)
|
|
915
|
+
.then((data: v1.DashboardDeleteResponse) => {
|
|
916
|
+
console.log("Dashboard deleted");
|
|
917
|
+
})
|
|
918
|
+
.catch((error: any) => console.error(error));
|
|
919
|
+
```
|
|
920
|
+
|
|
921
|
+
### Hosts API
|
|
922
|
+
|
|
923
|
+
#### List Hosts
|
|
924
|
+
|
|
925
|
+
Basic host listing:
|
|
926
|
+
|
|
927
|
+
```typescript
|
|
928
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
929
|
+
|
|
930
|
+
const configuration = client.createConfiguration();
|
|
931
|
+
const apiInstance = new v1.HostsApi(configuration);
|
|
932
|
+
|
|
933
|
+
apiInstance.listHosts()
|
|
934
|
+
.then((data: v1.HostListResponse) => {
|
|
935
|
+
console.log(`Total hosts: ${data.totalMatching}`);
|
|
936
|
+
data.hostList?.forEach(host => {
|
|
937
|
+
console.log(`Host: ${host.name}, Up: ${host.up}`);
|
|
938
|
+
});
|
|
939
|
+
})
|
|
940
|
+
.catch((error: any) => console.error(error));
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
Advanced host filtering:
|
|
944
|
+
|
|
945
|
+
```typescript
|
|
946
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
947
|
+
|
|
948
|
+
const configuration = client.createConfiguration();
|
|
949
|
+
const apiInstance = new v1.HostsApi(configuration);
|
|
950
|
+
|
|
951
|
+
const params: v1.HostsApiListHostsRequest = {
|
|
952
|
+
filter: "env:production",
|
|
953
|
+
sortField: "cpu",
|
|
954
|
+
sortDir: "desc",
|
|
955
|
+
start: 0,
|
|
956
|
+
count: 100,
|
|
957
|
+
from: Math.floor(Date.now() / 1000) - 3600
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
apiInstance.listHosts(params)
|
|
961
|
+
.then((data: v1.HostListResponse) => {
|
|
962
|
+
console.log("Production hosts sorted by CPU:");
|
|
963
|
+
data.hostList?.forEach(host => {
|
|
964
|
+
console.log(`${host.name}: CPU ${host.metrics?.cpu}%`);
|
|
965
|
+
});
|
|
966
|
+
})
|
|
967
|
+
.catch((error: any) => console.error(error));
|
|
968
|
+
```
|
|
969
|
+
|
|
970
|
+
#### Get Host Totals
|
|
971
|
+
|
|
972
|
+
```typescript
|
|
973
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
974
|
+
|
|
975
|
+
const configuration = client.createConfiguration();
|
|
976
|
+
const apiInstance = new v1.HostsApi(configuration);
|
|
977
|
+
|
|
978
|
+
const params: v1.HostsApiGetHostTotalsRequest = {
|
|
979
|
+
from: Math.floor(Date.now() / 1000) - 3600
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
apiInstance.getHostTotals(params)
|
|
983
|
+
.then((data: v1.HostTotals) => {
|
|
984
|
+
console.log("Total up hosts:", data.totalUp);
|
|
985
|
+
console.log("Total active hosts:", data.totalActive);
|
|
986
|
+
})
|
|
987
|
+
.catch((error: any) => console.error(error));
|
|
988
|
+
```
|
|
989
|
+
|
|
990
|
+
### Tags API
|
|
991
|
+
|
|
992
|
+
#### Get Host Tags
|
|
993
|
+
|
|
994
|
+
```typescript
|
|
995
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
996
|
+
|
|
997
|
+
const configuration = client.createConfiguration();
|
|
998
|
+
const apiInstance = new v1.TagsApi(configuration);
|
|
999
|
+
|
|
1000
|
+
const params: v1.TagsApiGetHostTagsRequest = {
|
|
1001
|
+
hostName: "app-server-1"
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
apiInstance.getHostTags(params)
|
|
1005
|
+
.then((data: v1.HostTags) => {
|
|
1006
|
+
console.log("Tags for host:", data.tags);
|
|
1007
|
+
})
|
|
1008
|
+
.catch((error: any) => console.error(error));
|
|
1009
|
+
```
|
|
1010
|
+
|
|
1011
|
+
#### Update Host Tags
|
|
1012
|
+
|
|
1013
|
+
```typescript
|
|
1014
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1015
|
+
|
|
1016
|
+
const configuration = client.createConfiguration();
|
|
1017
|
+
const apiInstance = new v1.TagsApi(configuration);
|
|
1018
|
+
|
|
1019
|
+
const params: v1.TagsApiUpdateHostTagsRequest = {
|
|
1020
|
+
hostName: "app-server-1",
|
|
1021
|
+
body: {
|
|
1022
|
+
tags: [
|
|
1023
|
+
"env:production",
|
|
1024
|
+
"service:api",
|
|
1025
|
+
"version:2.0.0",
|
|
1026
|
+
"team:platform"
|
|
1027
|
+
]
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
apiInstance.updateHostTags(params)
|
|
1032
|
+
.then((data: v1.HostTags) => {
|
|
1033
|
+
console.log("Host tags updated");
|
|
1034
|
+
})
|
|
1035
|
+
.catch((error: any) => console.error(error));
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
#### Create Host Tags
|
|
1039
|
+
|
|
1040
|
+
```typescript
|
|
1041
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1042
|
+
|
|
1043
|
+
const configuration = client.createConfiguration();
|
|
1044
|
+
const apiInstance = new v1.TagsApi(configuration);
|
|
1045
|
+
|
|
1046
|
+
const params: v1.TagsApiCreateHostTagsRequest = {
|
|
1047
|
+
hostName: "app-server-2",
|
|
1048
|
+
body: {
|
|
1049
|
+
tags: ["env:staging", "service:api"]
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
apiInstance.createHostTags(params)
|
|
1054
|
+
.then((data: v1.HostTags) => {
|
|
1055
|
+
console.log("Tags created for new host");
|
|
1056
|
+
})
|
|
1057
|
+
.catch((error: any) => console.error(error));
|
|
1058
|
+
```
|
|
1059
|
+
|
|
1060
|
+
#### Delete Host Tags
|
|
1061
|
+
|
|
1062
|
+
```typescript
|
|
1063
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1064
|
+
|
|
1065
|
+
const configuration = client.createConfiguration();
|
|
1066
|
+
const apiInstance = new v1.TagsApi(configuration);
|
|
1067
|
+
|
|
1068
|
+
const params: v1.TagsApiDeleteHostTagsRequest = {
|
|
1069
|
+
hostName: "app-server-1"
|
|
1070
|
+
};
|
|
1071
|
+
|
|
1072
|
+
apiInstance.deleteHostTags(params)
|
|
1073
|
+
.then(() => {
|
|
1074
|
+
console.log("All tags removed from host");
|
|
1075
|
+
})
|
|
1076
|
+
.catch((error: any) => console.error(error));
|
|
1077
|
+
```
|
|
1078
|
+
|
|
1079
|
+
### Service Checks API
|
|
1080
|
+
|
|
1081
|
+
#### Submit Service Check
|
|
1082
|
+
|
|
1083
|
+
Basic service check:
|
|
1084
|
+
|
|
1085
|
+
```typescript
|
|
1086
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1087
|
+
|
|
1088
|
+
const configuration = client.createConfiguration();
|
|
1089
|
+
const apiInstance = new v1.ServiceChecksApi(configuration);
|
|
1090
|
+
|
|
1091
|
+
const params: v1.ServiceChecksApiSubmitServiceCheckRequest = {
|
|
1092
|
+
body: [
|
|
1093
|
+
{
|
|
1094
|
+
check: "app.health",
|
|
1095
|
+
hostName: "app-server-1",
|
|
1096
|
+
status: 0, // 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN
|
|
1097
|
+
tags: ["env:production"]
|
|
1098
|
+
}
|
|
1099
|
+
]
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
apiInstance.submitServiceCheck(params)
|
|
1103
|
+
.then((data: v1.IntakePayloadAccepted) => {
|
|
1104
|
+
console.log("Service check submitted");
|
|
1105
|
+
})
|
|
1106
|
+
.catch((error: any) => console.error(error));
|
|
1107
|
+
```
|
|
1108
|
+
|
|
1109
|
+
Advanced service check with message:
|
|
1110
|
+
|
|
1111
|
+
```typescript
|
|
1112
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1113
|
+
|
|
1114
|
+
const configuration = client.createConfiguration();
|
|
1115
|
+
const apiInstance = new v1.ServiceChecksApi(configuration);
|
|
1116
|
+
|
|
1117
|
+
const params: v1.ServiceChecksApiSubmitServiceCheckRequest = {
|
|
1118
|
+
body: [
|
|
1119
|
+
{
|
|
1120
|
+
check: "database.connection",
|
|
1121
|
+
hostName: "db-server-1",
|
|
1122
|
+
status: 2, // CRITICAL
|
|
1123
|
+
timestamp: Math.floor(Date.now() / 1000),
|
|
1124
|
+
message: "Database connection failed: timeout after 30s",
|
|
1125
|
+
tags: ["env:production", "service:postgres"]
|
|
1126
|
+
}
|
|
1127
|
+
]
|
|
1128
|
+
};
|
|
1129
|
+
|
|
1130
|
+
apiInstance.submitServiceCheck(params)
|
|
1131
|
+
.then((data: v1.IntakePayloadAccepted) => {
|
|
1132
|
+
console.log("Critical service check submitted");
|
|
1133
|
+
})
|
|
1134
|
+
.catch((error: any) => console.error(error));
|
|
1135
|
+
```
|
|
1136
|
+
|
|
1137
|
+
### Downtimes API (v2)
|
|
1138
|
+
|
|
1139
|
+
#### Create Downtime
|
|
1140
|
+
|
|
1141
|
+
Basic downtime creation:
|
|
1142
|
+
|
|
1143
|
+
```typescript
|
|
1144
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1145
|
+
|
|
1146
|
+
const configuration = client.createConfiguration();
|
|
1147
|
+
const apiInstance = new v2.DowntimesApi(configuration);
|
|
1148
|
+
|
|
1149
|
+
const params: v2.DowntimesApiCreateDowntimeRequest = {
|
|
1150
|
+
body: {
|
|
1151
|
+
data: {
|
|
1152
|
+
type: "downtime",
|
|
1153
|
+
attributes: {
|
|
1154
|
+
scope: "env:staging",
|
|
1155
|
+
message: "Planned maintenance window",
|
|
1156
|
+
schedule: {
|
|
1157
|
+
start: new Date(Date.now() + 3600000).toISOString(),
|
|
1158
|
+
end: new Date(Date.now() + 7200000).toISOString()
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
apiInstance.createDowntime(params)
|
|
1166
|
+
.then((data: v2.DowntimeResponse) => {
|
|
1167
|
+
console.log("Downtime created:", data.data?.id);
|
|
1168
|
+
})
|
|
1169
|
+
.catch((error: any) => console.error(error));
|
|
1170
|
+
```
|
|
1171
|
+
|
|
1172
|
+
Advanced recurring downtime:
|
|
1173
|
+
|
|
1174
|
+
```typescript
|
|
1175
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1176
|
+
|
|
1177
|
+
const configuration = client.createConfiguration();
|
|
1178
|
+
const apiInstance = new v2.DowntimesApi(configuration);
|
|
1179
|
+
|
|
1180
|
+
const params: v2.DowntimesApiCreateDowntimeRequest = {
|
|
1181
|
+
body: {
|
|
1182
|
+
data: {
|
|
1183
|
+
type: "downtime",
|
|
1184
|
+
attributes: {
|
|
1185
|
+
scope: "host:app-server-*",
|
|
1186
|
+
message: "Weekly maintenance window every Sunday",
|
|
1187
|
+
monitorIdentifier: {
|
|
1188
|
+
monitorTags: ["maintenance:auto"]
|
|
1189
|
+
},
|
|
1190
|
+
schedule: {
|
|
1191
|
+
start: new Date().toISOString(),
|
|
1192
|
+
recurrence: {
|
|
1193
|
+
type: "weeks",
|
|
1194
|
+
period: 1,
|
|
1195
|
+
weekDays: ["Sun"]
|
|
1196
|
+
},
|
|
1197
|
+
timezone: "America/New_York"
|
|
1198
|
+
},
|
|
1199
|
+
notifyEndStates: ["alert", "warn"],
|
|
1200
|
+
notifyEndTypes: ["expired", "canceled"]
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
|
|
1206
|
+
apiInstance.createDowntime(params)
|
|
1207
|
+
.then((data: v2.DowntimeResponse) => {
|
|
1208
|
+
console.log("Recurring downtime created");
|
|
1209
|
+
})
|
|
1210
|
+
.catch((error: any) => console.error(error));
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
#### List Downtimes
|
|
1214
|
+
|
|
1215
|
+
```typescript
|
|
1216
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1217
|
+
|
|
1218
|
+
const configuration = client.createConfiguration();
|
|
1219
|
+
const apiInstance = new v2.DowntimesApi(configuration);
|
|
1220
|
+
|
|
1221
|
+
apiInstance.listDowntimes()
|
|
1222
|
+
.then((data: v2.ListDowntimesResponse) => {
|
|
1223
|
+
data.data?.forEach(downtime => {
|
|
1224
|
+
console.log(`ID: ${downtime.id}, Scope: ${downtime.attributes?.scope}`);
|
|
1225
|
+
});
|
|
1226
|
+
})
|
|
1227
|
+
.catch((error: any) => console.error(error));
|
|
1228
|
+
```
|
|
1229
|
+
|
|
1230
|
+
#### Cancel Downtime
|
|
1231
|
+
|
|
1232
|
+
```typescript
|
|
1233
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1234
|
+
|
|
1235
|
+
const configuration = client.createConfiguration();
|
|
1236
|
+
const apiInstance = new v2.DowntimesApi(configuration);
|
|
1237
|
+
|
|
1238
|
+
const params: v2.DowntimesApiCancelDowntimeRequest = {
|
|
1239
|
+
downtimeId: "downtime-id-here"
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1242
|
+
apiInstance.cancelDowntime(params)
|
|
1243
|
+
.then(() => {
|
|
1244
|
+
console.log("Downtime cancelled");
|
|
1245
|
+
})
|
|
1246
|
+
.catch((error: any) => console.error(error));
|
|
1247
|
+
```
|
|
1248
|
+
|
|
1249
|
+
### Incidents API (v2)
|
|
1250
|
+
|
|
1251
|
+
#### Create Incident
|
|
1252
|
+
|
|
1253
|
+
```typescript
|
|
1254
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1255
|
+
|
|
1256
|
+
const configuration = client.createConfiguration();
|
|
1257
|
+
configuration.unstableOperations["v2.createIncident"] = true;
|
|
1258
|
+
|
|
1259
|
+
const apiInstance = new v2.IncidentsApi(configuration);
|
|
1260
|
+
|
|
1261
|
+
const params: v2.IncidentsApiCreateIncidentRequest = {
|
|
1262
|
+
body: {
|
|
1263
|
+
data: {
|
|
1264
|
+
type: "incidents",
|
|
1265
|
+
attributes: {
|
|
1266
|
+
title: "Production API Outage",
|
|
1267
|
+
customerImpacted: true,
|
|
1268
|
+
fields: {
|
|
1269
|
+
severity: {
|
|
1270
|
+
type: "dropdown",
|
|
1271
|
+
value: "SEV-1"
|
|
1272
|
+
},
|
|
1273
|
+
state: {
|
|
1274
|
+
type: "dropdown",
|
|
1275
|
+
value: "active"
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
apiInstance.createIncident(params)
|
|
1284
|
+
.then((data: v2.IncidentResponse) => {
|
|
1285
|
+
console.log("Incident created:", data.data?.id);
|
|
1286
|
+
})
|
|
1287
|
+
.catch((error: any) => console.error(error));
|
|
1288
|
+
```
|
|
1289
|
+
|
|
1290
|
+
#### List Incidents
|
|
1291
|
+
|
|
1292
|
+
```typescript
|
|
1293
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1294
|
+
|
|
1295
|
+
const configuration = client.createConfiguration();
|
|
1296
|
+
configuration.unstableOperations["v2.listIncidents"] = true;
|
|
1297
|
+
|
|
1298
|
+
const apiInstance = new v2.IncidentsApi(configuration);
|
|
1299
|
+
|
|
1300
|
+
apiInstance.listIncidents()
|
|
1301
|
+
.then((data: v2.IncidentsResponse) => {
|
|
1302
|
+
data.data?.forEach(incident => {
|
|
1303
|
+
console.log(`${incident.id}: ${incident.attributes?.title}`);
|
|
1304
|
+
});
|
|
1305
|
+
})
|
|
1306
|
+
.catch((error: any) => console.error(error));
|
|
1307
|
+
```
|
|
1308
|
+
|
|
1309
|
+
### SLOs API (Service Level Objectives)
|
|
1310
|
+
|
|
1311
|
+
#### Create SLO
|
|
1312
|
+
|
|
1313
|
+
```typescript
|
|
1314
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1315
|
+
|
|
1316
|
+
const configuration = client.createConfiguration();
|
|
1317
|
+
const apiInstance = new v1.ServiceLevelObjectivesApi(configuration);
|
|
1318
|
+
|
|
1319
|
+
const params: v1.ServiceLevelObjectivesApiCreateSLORequest = {
|
|
1320
|
+
body: {
|
|
1321
|
+
type: "metric",
|
|
1322
|
+
name: "API Availability SLO",
|
|
1323
|
+
description: "99.9% availability for production API",
|
|
1324
|
+
thresholds: [
|
|
1325
|
+
{
|
|
1326
|
+
target: 99.9,
|
|
1327
|
+
targetDisplay: "99.9",
|
|
1328
|
+
timeframe: "30d",
|
|
1329
|
+
warning: 99.95
|
|
1330
|
+
}
|
|
1331
|
+
],
|
|
1332
|
+
query: {
|
|
1333
|
+
numerator: "sum:api.requests{status:ok}.as_count()",
|
|
1334
|
+
denominator: "sum:api.requests{*}.as_count()"
|
|
1335
|
+
},
|
|
1336
|
+
tags: ["service:api", "env:production"]
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1340
|
+
apiInstance.createSLO(params)
|
|
1341
|
+
.then((data: v1.SLOListResponse) => {
|
|
1342
|
+
console.log("SLO created:", data.data?.[0].id);
|
|
1343
|
+
})
|
|
1344
|
+
.catch((error: any) => console.error(error));
|
|
1345
|
+
```
|
|
1346
|
+
|
|
1347
|
+
#### List SLOs
|
|
1348
|
+
|
|
1349
|
+
```typescript
|
|
1350
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1351
|
+
|
|
1352
|
+
const configuration = client.createConfiguration();
|
|
1353
|
+
const apiInstance = new v1.ServiceLevelObjectivesApi(configuration);
|
|
1354
|
+
|
|
1355
|
+
const params: v1.ServiceLevelObjectivesApiListSLOsRequest = {
|
|
1356
|
+
tags: "service:api"
|
|
1357
|
+
};
|
|
1358
|
+
|
|
1359
|
+
apiInstance.listSLOs(params)
|
|
1360
|
+
.then((data: v1.SLOListResponse) => {
|
|
1361
|
+
data.data?.forEach(slo => {
|
|
1362
|
+
console.log(`${slo.name}: ${slo.thresholds?.[0].target}%`);
|
|
1363
|
+
});
|
|
1364
|
+
})
|
|
1365
|
+
.catch((error: any) => console.error(error));
|
|
1366
|
+
```
|
|
1367
|
+
|
|
1368
|
+
### Users API
|
|
1369
|
+
|
|
1370
|
+
#### List Users
|
|
1371
|
+
|
|
1372
|
+
```typescript
|
|
1373
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1374
|
+
|
|
1375
|
+
const configuration = client.createConfiguration();
|
|
1376
|
+
const apiInstance = new v2.UsersApi(configuration);
|
|
1377
|
+
|
|
1378
|
+
apiInstance.listUsers()
|
|
1379
|
+
.then((data: v2.UsersResponse) => {
|
|
1380
|
+
data.data?.forEach(user => {
|
|
1381
|
+
console.log(`${user.attributes?.name}: ${user.attributes?.email}`);
|
|
1382
|
+
});
|
|
1383
|
+
})
|
|
1384
|
+
.catch((error: any) => console.error(error));
|
|
1385
|
+
```
|
|
1386
|
+
|
|
1387
|
+
#### Create User
|
|
1388
|
+
|
|
1389
|
+
```typescript
|
|
1390
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1391
|
+
|
|
1392
|
+
const configuration = client.createConfiguration();
|
|
1393
|
+
const apiInstance = new v2.UsersApi(configuration);
|
|
1394
|
+
|
|
1395
|
+
const params: v2.UsersApiCreateUserRequest = {
|
|
1396
|
+
body: {
|
|
1397
|
+
data: {
|
|
1398
|
+
type: "users",
|
|
1399
|
+
attributes: {
|
|
1400
|
+
name: "John Doe",
|
|
1401
|
+
email: "john.doe@example.com"
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
|
|
1407
|
+
apiInstance.createUser(params)
|
|
1408
|
+
.then((data: v2.UserResponse) => {
|
|
1409
|
+
console.log("User created:", data.data?.id);
|
|
1410
|
+
})
|
|
1411
|
+
.catch((error: any) => console.error(error));
|
|
1412
|
+
```
|
|
1413
|
+
|
|
1414
|
+
## Error Handling
|
|
1415
|
+
|
|
1416
|
+
### Basic Error Handling
|
|
1417
|
+
|
|
1418
|
+
```typescript
|
|
1419
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1420
|
+
|
|
1421
|
+
const configuration = client.createConfiguration();
|
|
1422
|
+
const apiInstance = new v1.MonitorsApi(configuration);
|
|
1423
|
+
|
|
1424
|
+
apiInstance.listMonitors()
|
|
1425
|
+
.then((data: v1.Monitor[]) => {
|
|
1426
|
+
console.log("Success:", data);
|
|
1427
|
+
})
|
|
1428
|
+
.catch((error: any) => {
|
|
1429
|
+
if (error.response) {
|
|
1430
|
+
console.error("Status:", error.response.status);
|
|
1431
|
+
console.error("Body:", error.response.body);
|
|
1432
|
+
} else {
|
|
1433
|
+
console.error("Error:", error.message);
|
|
1434
|
+
}
|
|
1435
|
+
});
|
|
1436
|
+
```
|
|
1437
|
+
|
|
1438
|
+
### Advanced Error Handling with Retry
|
|
1439
|
+
|
|
1440
|
+
```typescript
|
|
1441
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1442
|
+
|
|
1443
|
+
const configurationOpts = {
|
|
1444
|
+
enableRetry: true,
|
|
1445
|
+
maxRetries: 3,
|
|
1446
|
+
backoffMultiplier: 2
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
1450
|
+
const apiInstance = new v1.MetricsApi(configuration);
|
|
1451
|
+
|
|
1452
|
+
async function submitMetricsWithRetry() {
|
|
1453
|
+
try {
|
|
1454
|
+
const params: v1.MetricsApiSubmitMetricsRequest = {
|
|
1455
|
+
body: {
|
|
1456
|
+
series: [{
|
|
1457
|
+
metric: "custom.metric",
|
|
1458
|
+
points: [[Math.floor(Date.now() / 1000), 100]]
|
|
1459
|
+
}]
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
const result = await apiInstance.submitMetrics(params);
|
|
1464
|
+
console.log("Metrics submitted successfully");
|
|
1465
|
+
return result;
|
|
1466
|
+
} catch (error: any) {
|
|
1467
|
+
if (error.response?.status === 429) {
|
|
1468
|
+
console.error("Rate limited - automatic retry will handle this");
|
|
1469
|
+
} else if (error.response?.status === 403) {
|
|
1470
|
+
console.error("Authentication failed - check API keys");
|
|
1471
|
+
} else if (error.response?.status === 400) {
|
|
1472
|
+
console.error("Bad request:", error.response.body);
|
|
1473
|
+
} else {
|
|
1474
|
+
console.error("Unexpected error:", error);
|
|
1475
|
+
}
|
|
1476
|
+
throw error;
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
submitMetricsWithRetry();
|
|
1481
|
+
```
|
|
1482
|
+
|
|
1483
|
+
## Pagination
|
|
1484
|
+
|
|
1485
|
+
### Manual Pagination
|
|
1486
|
+
|
|
1487
|
+
```typescript
|
|
1488
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1489
|
+
|
|
1490
|
+
const configuration = client.createConfiguration();
|
|
1491
|
+
const apiInstance = new v1.HostsApi(configuration);
|
|
1492
|
+
|
|
1493
|
+
async function getAllHosts() {
|
|
1494
|
+
const allHosts: any[] = [];
|
|
1495
|
+
let start = 0;
|
|
1496
|
+
const count = 100;
|
|
1497
|
+
let hasMore = true;
|
|
1498
|
+
|
|
1499
|
+
while (hasMore) {
|
|
1500
|
+
const params: v1.HostsApiListHostsRequest = {
|
|
1501
|
+
start: start,
|
|
1502
|
+
count: count
|
|
1503
|
+
};
|
|
1504
|
+
|
|
1505
|
+
const data = await apiInstance.listHosts(params);
|
|
1506
|
+
|
|
1507
|
+
if (data.hostList) {
|
|
1508
|
+
allHosts.push(...data.hostList);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
start += count;
|
|
1512
|
+
hasMore = (data.hostList?.length || 0) === count;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
return allHosts;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
getAllHosts().then(hosts => {
|
|
1519
|
+
console.log(`Retrieved ${hosts.length} total hosts`);
|
|
1520
|
+
});
|
|
1521
|
+
```
|
|
1522
|
+
|
|
1523
|
+
### Automatic Pagination with Async Iterator
|
|
1524
|
+
|
|
1525
|
+
```typescript
|
|
1526
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1527
|
+
|
|
1528
|
+
const configuration = client.createConfiguration();
|
|
1529
|
+
const apiInstance = new v2.LogsApi(configuration);
|
|
1530
|
+
|
|
1531
|
+
async function processAllLogs() {
|
|
1532
|
+
const params: v2.LogsApiListLogsRequest = {
|
|
1533
|
+
body: {
|
|
1534
|
+
filter: {
|
|
1535
|
+
query: "service:api",
|
|
1536
|
+
from: new Date(Date.now() - 3600000).toISOString(),
|
|
1537
|
+
to: new Date().toISOString()
|
|
1538
|
+
},
|
|
1539
|
+
page: {
|
|
1540
|
+
limit: 100
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1545
|
+
// Some endpoints support pagination
|
|
1546
|
+
for await (const log of apiInstance.listLogsWithPagination(params)) {
|
|
1547
|
+
console.log(log.attributes?.message);
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
processAllLogs();
|
|
1552
|
+
```
|
|
1553
|
+
|
|
1554
|
+
## Async/Await Pattern
|
|
1555
|
+
|
|
1556
|
+
```typescript
|
|
1557
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1558
|
+
|
|
1559
|
+
const configuration = client.createConfiguration();
|
|
1560
|
+
|
|
1561
|
+
async function monitorWorkflow() {
|
|
1562
|
+
const monitorsApi = new v1.MonitorsApi(configuration);
|
|
1563
|
+
const eventsApi = new v1.EventsApi(configuration);
|
|
1564
|
+
|
|
1565
|
+
try {
|
|
1566
|
+
// Create monitor
|
|
1567
|
+
const monitor = await monitorsApi.createMonitor({
|
|
1568
|
+
body: {
|
|
1569
|
+
type: "metric alert",
|
|
1570
|
+
query: "avg(last_5m):avg:system.cpu.user{*} > 80",
|
|
1571
|
+
name: "High CPU Alert",
|
|
1572
|
+
message: "CPU is high @slack-alerts"
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
|
|
1576
|
+
console.log("Monitor created:", monitor.id);
|
|
1577
|
+
|
|
1578
|
+
// Post event about monitor creation
|
|
1579
|
+
await eventsApi.createEvent({
|
|
1580
|
+
body: {
|
|
1581
|
+
title: "Monitor Created",
|
|
1582
|
+
text: `Created new monitor: ${monitor.name}`,
|
|
1583
|
+
tags: ["automation", "monitoring"]
|
|
1584
|
+
}
|
|
1585
|
+
});
|
|
1586
|
+
|
|
1587
|
+
console.log("Event posted");
|
|
1588
|
+
|
|
1589
|
+
// List all monitors
|
|
1590
|
+
const monitors = await monitorsApi.listMonitors();
|
|
1591
|
+
console.log(`Total monitors: ${monitors.length}`);
|
|
1592
|
+
|
|
1593
|
+
} catch (error) {
|
|
1594
|
+
console.error("Workflow failed:", error);
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
monitorWorkflow();
|
|
1599
|
+
```
|
|
1600
|
+
|
|
1601
|
+
## TypeScript Types
|
|
1602
|
+
|
|
1603
|
+
The package includes full TypeScript definitions:
|
|
1604
|
+
|
|
1605
|
+
```typescript
|
|
1606
|
+
import { client, v1, v2 } from '@datadog/datadog-api-client';
|
|
1607
|
+
|
|
1608
|
+
// Configuration type
|
|
1609
|
+
const config: client.Configuration = client.createConfiguration();
|
|
1610
|
+
|
|
1611
|
+
// Monitor type
|
|
1612
|
+
const monitor: v1.Monitor = {
|
|
1613
|
+
type: "metric alert",
|
|
1614
|
+
query: "avg(last_5m):avg:system.cpu.user{*} > 80",
|
|
1615
|
+
name: "CPU Alert",
|
|
1616
|
+
message: "High CPU usage detected"
|
|
1617
|
+
};
|
|
1618
|
+
|
|
1619
|
+
// Metric series type
|
|
1620
|
+
const series: v1.Series = {
|
|
1621
|
+
metric: "custom.metric",
|
|
1622
|
+
points: [[Math.floor(Date.now() / 1000), 100]],
|
|
1623
|
+
type: "gauge",
|
|
1624
|
+
host: "server-1",
|
|
1625
|
+
tags: ["env:prod"]
|
|
1626
|
+
};
|
|
1627
|
+
|
|
1628
|
+
// Event type
|
|
1629
|
+
const event: v1.Event = {
|
|
1630
|
+
title: "Deployment",
|
|
1631
|
+
text: "Version deployed",
|
|
1632
|
+
dateHappened: Math.floor(Date.now() / 1000),
|
|
1633
|
+
priority: "normal",
|
|
1634
|
+
tags: ["deployment"],
|
|
1635
|
+
alertType: "info"
|
|
1636
|
+
};
|
|
1637
|
+
```
|
|
1638
|
+
|
|
1639
|
+
## Rate Limiting
|
|
1640
|
+
|
|
1641
|
+
Datadog API enforces rate limits. Enable automatic retry on rate limiting:
|
|
1642
|
+
|
|
1643
|
+
```typescript
|
|
1644
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1645
|
+
|
|
1646
|
+
const configurationOpts = {
|
|
1647
|
+
enableRetry: true,
|
|
1648
|
+
maxRetries: 5,
|
|
1649
|
+
backoffMultiplier: 2,
|
|
1650
|
+
backoffBase: 2
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1653
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
1654
|
+
|
|
1655
|
+
// The client will automatically retry on 429 responses
|
|
1656
|
+
const apiInstance = new v1.MetricsApi(configuration);
|
|
1657
|
+
```
|
|
1658
|
+
|
|
1659
|
+
## Request Timeouts
|
|
1660
|
+
|
|
1661
|
+
Configure custom request timeouts:
|
|
1662
|
+
|
|
1663
|
+
```typescript
|
|
1664
|
+
import { client } from '@datadog/datadog-api-client';
|
|
1665
|
+
|
|
1666
|
+
const configurationOpts = {
|
|
1667
|
+
httpConfig: {
|
|
1668
|
+
timeout: 60000 // 60 seconds
|
|
1669
|
+
}
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1672
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
1673
|
+
```
|
|
1674
|
+
|
|
1675
|
+
## Compression
|
|
1676
|
+
|
|
1677
|
+
Enable compression for large payloads:
|
|
1678
|
+
|
|
1679
|
+
```typescript
|
|
1680
|
+
import { client, v2 } from '@datadog/datadog-api-client';
|
|
1681
|
+
import { compressSync } from 'zstd.ts';
|
|
1682
|
+
|
|
1683
|
+
const configurationOpts = {
|
|
1684
|
+
zstdCompressorCallback: (body: string) =>
|
|
1685
|
+
compressSync({ input: Buffer.from(body, "utf8") })
|
|
1686
|
+
};
|
|
1687
|
+
|
|
1688
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
1689
|
+
const apiInstance = new v2.MetricsApi(configuration);
|
|
1690
|
+
|
|
1691
|
+
// Submit with compression
|
|
1692
|
+
const params: v2.MetricsApiSubmitMetricsRequest = {
|
|
1693
|
+
body: { series: [/* large payload */] },
|
|
1694
|
+
contentEncoding: "zstd1"
|
|
1695
|
+
};
|
|
1696
|
+
|
|
1697
|
+
apiInstance.submitMetrics(params);
|
|
1698
|
+
```
|
|
1699
|
+
|
|
1700
|
+
## Debug Logging
|
|
1701
|
+
|
|
1702
|
+
Enable debug logging to see request/response details:
|
|
1703
|
+
|
|
1704
|
+
```typescript
|
|
1705
|
+
import { client } from '@datadog/datadog-api-client';
|
|
1706
|
+
|
|
1707
|
+
const configurationOpts = {
|
|
1708
|
+
debug: true
|
|
1709
|
+
};
|
|
1710
|
+
|
|
1711
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
1712
|
+
|
|
1713
|
+
// All API calls will log request and response details
|
|
1714
|
+
```
|
|
1715
|
+
|
|
1716
|
+
## Canceling Requests
|
|
1717
|
+
|
|
1718
|
+
Use AbortController to cancel in-flight requests:
|
|
1719
|
+
|
|
1720
|
+
```typescript
|
|
1721
|
+
import { client, v1 } from '@datadog/datadog-api-client';
|
|
1722
|
+
import AbortController from 'abort-controller';
|
|
1723
|
+
|
|
1724
|
+
const controller = new AbortController();
|
|
1725
|
+
|
|
1726
|
+
const configurationOpts = {
|
|
1727
|
+
httpConfig: { signal: controller.signal }
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
const configuration = client.createConfiguration(configurationOpts);
|
|
1731
|
+
const apiInstance = new v1.MonitorsApi(configuration);
|
|
1732
|
+
|
|
1733
|
+
// Start request
|
|
1734
|
+
apiInstance.listMonitors()
|
|
1735
|
+
.then((data) => console.log(data))
|
|
1736
|
+
.catch((error) => console.error("Request cancelled or failed"));
|
|
1737
|
+
|
|
1738
|
+
// Cancel after 1 second
|
|
1739
|
+
setTimeout(() => controller.abort(), 1000);
|
|
1740
|
+
```
|