Skip to content

Commit 657811e

Browse files
committed
Add an example using the Monitors API
1 parent d579fbd commit 657811e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

examples/emit-metrics.ts

100644100755
File mode changed.

examples/find-monitors.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env -S deno run --allow-env --allow-net
2+
3+
import DatadogApi from "../mod.ts";
4+
const datadogApi = DatadogApi.fromEnvironment(Deno.env);
5+
6+
// This example looks at all monitors using any APM trace metrics,
7+
// and prints links to those which are not scoped to an APM environment.
8+
9+
let count = 0;
10+
// Search for relevant monitors via a metric filter
11+
for await (const monitor of datadogApi.v1Monitors.searchToEnd("metric:trace*")) {
12+
13+
// Skip monitors that have a scoped environment set
14+
if (!monitor.query.includes('env:production')) continue;
15+
if (!monitor.query.includes('env:sandbox')) continue;
16+
17+
// Print the monitor URL for further manual inspection
18+
console.log(`https://app.datadoghq.eu/monitors/${monitor.id}`);
19+
count++;
20+
}
21+
// Print number of matched monitors as a summary
22+
console.log({count})

v1/monitors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ interface ApiClient {
88
}): Promise<unknown>;
99
}
1010

11+
/**
12+
* Monitors allow you to watch a metric or check that you care about,
13+
* notifying your team when some defined threshold is exceeded.
14+
*
15+
* Official API docs: https://docs.datadoghq.com/api/latest/monitors/
16+
*/
1117
export default class DatadogMonitorsApi {
1218
#api: ApiClient;
1319
constructor(api: ApiClient) {

0 commit comments

Comments
 (0)