Skip to content

Commit

Permalink
Add an example using the Monitors API
Browse files Browse the repository at this point in the history
  • Loading branch information
danopia committed Nov 25, 2021
1 parent d579fbd commit 657811e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Empty file modified examples/emit-metrics.ts
100644 → 100755
Empty file.
22 changes: 22 additions & 0 deletions examples/find-monitors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env -S deno run --allow-env --allow-net

import DatadogApi from "../mod.ts";
const datadogApi = DatadogApi.fromEnvironment(Deno.env);

// This example looks at all monitors using any APM trace metrics,
// and prints links to those which are not scoped to an APM environment.

let count = 0;
// Search for relevant monitors via a metric filter
for await (const monitor of datadogApi.v1Monitors.searchToEnd("metric:trace*")) {

// Skip monitors that have a scoped environment set
if (!monitor.query.includes('env:production')) continue;
if (!monitor.query.includes('env:sandbox')) continue;

// Print the monitor URL for further manual inspection
console.log(`https://app.datadoghq.eu/monitors/${monitor.id}`);
count++;
}
// Print number of matched monitors as a summary
console.log({count})
6 changes: 6 additions & 0 deletions v1/monitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ interface ApiClient {
}): Promise<unknown>;
}

/**
* Monitors allow you to watch a metric or check that you care about,
* notifying your team when some defined threshold is exceeded.
*
* Official API docs: https://docs.datadoghq.com/api/latest/monitors/
*/
export default class DatadogMonitorsApi {
#api: ApiClient;
constructor(api: ApiClient) {
Expand Down

0 comments on commit 657811e

Please sign in to comment.