Skip to content

DigitalOcean.Insights reference

Source: packages/digitalocean/src/Insights/AlertRule.ts

An Insights alert rule: a metric query, thresholds, and the channels to notify when the metric crosses them. Every field updates in place.

const oncall = yield* DigitalOcean.Insights.NotificationChannel("oncall", {
email: { to: "oncall@example.com" },
});
yield* DigitalOcean.Insights.AlertRule("high-cpu", {
metric: "do.droplets.cpu_utilization",
resourceUrns: [host.urn],
thresholds: { operator: "THRESHOLD_OPERATOR_GREATER_THAN", warning: 80, critical: 95 },
notify: [{ channelId: oncall.channelId }],
});

Source: packages/digitalocean/src/Insights/Dashboard.ts

An Insights dashboard of metric panels. The whole definition updates in place.

yield* DigitalOcean.Insights.Dashboard("overview", {
definition: {
kind: "Dashboard",
metadata: { name: "overview" },
spec: { display: { name: "Overview" }, panels: {}, layouts: [] },
},
});

Source: packages/digitalocean/src/Insights/NotificationChannel.ts

Where Insights alert rules send their notifications: an email address, a Slack channel, or a webhook. The name, destination and credentials update in place; changing the kind of destination replaces the channel.

Email the on-call address

const oncall = yield* DigitalOcean.Insights.NotificationChannel("oncall", {
email: { to: "oncall@example.com" },
});

Post to Slack

const webhookUrl = yield* Config.Redacted("SLACK_WEBHOOK_URL");
yield* DigitalOcean.Insights.NotificationChannel("alerts", {
slack: { channel: "#alerts", webhookUrl },
});

Source: packages/digitalocean/src/Insights/QueryMetrics.ts

Evaluates a PromQL expression at one instant over a region’s metrics. Pass a personal access token with the insights:read scope; it reaches the host as a secret.

export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const token = yield* Config.Redacted("INSIGHTS_TOKEN");
const query = yield* DigitalOcean.Insights.QueryMetrics({ token });
return {
fetch: Effect.gen(function* () {
const result = yield* query({ region: "nyc3", query: "up" });
return yield* HttpServerResponse.json(result);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Insights.QueryMetricsHttp)),
) {}

Source: packages/digitalocean/src/Insights/QueryMetricsHttp.ts Kind: Layer · Provides: DigitalOcean.Insights.QueryMetrics

QueryMetrics over the Insights API.

Source: packages/digitalocean/src/Insights/QueryMetricsRange.ts

Evaluates a PromQL expression over a time range, one sample per step. Pass a personal access token with the insights:read scope; it reaches the host as a secret.

export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const token = yield* Config.Redacted("INSIGHTS_TOKEN");
const query = yield* DigitalOcean.Insights.QueryMetricsRange({ token });
return {
fetch: Effect.gen(function* () {
const now = Math.floor(Date.now() / 1000);
const result = yield* query({
region: "nyc3",
query: "up",
start: String(now - 3600),
end: String(now),
step: "60s",
});
return yield* HttpServerResponse.json(result);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Insights.QueryMetricsRangeHttp)),
) {}

Source: packages/digitalocean/src/Insights/QueryMetricsRangeHttp.ts Kind: Layer · Provides: DigitalOcean.Insights.QueryMetricsRange

QueryMetricsRange over the Insights API.

Source: packages/digitalocean/src/Insights/SearchLogs.ts

Searches a region’s logs in a time range, with an optional filter. Pass a personal access token with the insights:read scope; it reaches the host as a secret.

export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const token = yield* Config.Redacted("INSIGHTS_TOKEN");
const search = yield* DigitalOcean.Insights.SearchLogs({ token });
return {
fetch: Effect.gen(function* () {
const logs = yield* search({
region: "nyc3",
time_range: { from: { relative: "1h" }, to: { relative: "now" } },
});
return yield* HttpServerResponse.json(logs);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Insights.SearchLogsHttp)),
) {}

Source: packages/digitalocean/src/Insights/SearchLogsHttp.ts Kind: Layer · Provides: DigitalOcean.Insights.SearchLogs

SearchLogs over the Insights API.

Source: packages/digitalocean/src/Insights/SearchSpans.ts

Searches a region’s spans in a time range. Pass a personal access token with the insights:read scope; it reaches the host as a secret.

export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const token = yield* Config.Redacted("INSIGHTS_TOKEN");
const search = yield* DigitalOcean.Insights.SearchSpans({ token });
return {
fetch: Effect.gen(function* () {
const found = yield* search({
region: "nyc3",
time_range: { from: { relative: "1h" }, to: { relative: "now" } },
});
return yield* HttpServerResponse.json(found);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Insights.SearchSpansHttp)),
) {}

Source: packages/digitalocean/src/Insights/SearchSpansHttp.ts Kind: Layer · Provides: DigitalOcean.Insights.SearchSpans

SearchSpans over the Insights API.

Source: packages/digitalocean/src/Insights/SearchTraces.ts

Searches a region’s traces in a time range. Pass a personal access token with the insights:read scope; it reaches the host as a secret.

export default class Api extends DigitalOcean.App<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
const token = yield* Config.Redacted("INSIGHTS_TOKEN");
const search = yield* DigitalOcean.Insights.SearchTraces({ token });
return {
fetch: Effect.gen(function* () {
const found = yield* search({
region: "nyc3",
time_range: { from: { relative: "1h" }, to: { relative: "now" } },
});
return yield* HttpServerResponse.json(found);
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(DigitalOcean.Insights.SearchTracesHttp)),
) {}

Source: packages/digitalocean/src/Insights/SearchTracesHttp.ts Kind: Layer · Provides: DigitalOcean.Insights.SearchTraces

SearchTraces over the Insights API.