DigitalOcean.Insights reference
AlertRule
Section titled “AlertRule”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.
AlertRule: Alerting on a Metric
Section titled “AlertRule: Alerting on a Metric”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 }],});Dashboard
Section titled “Dashboard”Source:
packages/digitalocean/src/Insights/Dashboard.ts
An Insights dashboard of metric panels. The whole definition updates in place.
Dashboard: Creating a Dashboard
Section titled “Dashboard: Creating a Dashboard”yield* DigitalOcean.Insights.Dashboard("overview", { definition: { kind: "Dashboard", metadata: { name: "overview" }, spec: { display: { name: "Overview" }, panels: {}, layouts: [] }, },});NotificationChannel
Section titled “NotificationChannel”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.
NotificationChannel: Creating a Channel
Section titled “NotificationChannel: Creating a 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 },});QueryMetrics
Section titled “QueryMetrics”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.
QueryMetrics: Examples
Section titled “QueryMetrics: Examples”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)),) {}QueryMetricsHttp
Section titled “QueryMetricsHttp”Source:
packages/digitalocean/src/Insights/QueryMetricsHttp.tsKind: Layer · Provides:DigitalOcean.Insights.QueryMetrics
QueryMetrics over the Insights API.
QueryMetricsRange
Section titled “QueryMetricsRange”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.
QueryMetricsRange: Examples
Section titled “QueryMetricsRange: Examples”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)),) {}QueryMetricsRangeHttp
Section titled “QueryMetricsRangeHttp”Source:
packages/digitalocean/src/Insights/QueryMetricsRangeHttp.tsKind: Layer · Provides:DigitalOcean.Insights.QueryMetricsRange
QueryMetricsRange over the Insights API.
SearchLogs
Section titled “SearchLogs”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.
SearchLogs: Examples
Section titled “SearchLogs: Examples”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)),) {}SearchLogsHttp
Section titled “SearchLogsHttp”Source:
packages/digitalocean/src/Insights/SearchLogsHttp.tsKind: Layer · Provides:DigitalOcean.Insights.SearchLogs
SearchLogs over the Insights API.
SearchSpans
Section titled “SearchSpans”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.
SearchSpans: Examples
Section titled “SearchSpans: Examples”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)),) {}SearchSpansHttp
Section titled “SearchSpansHttp”Source:
packages/digitalocean/src/Insights/SearchSpansHttp.tsKind: Layer · Provides:DigitalOcean.Insights.SearchSpans
SearchSpans over the Insights API.
SearchTraces
Section titled “SearchTraces”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.
SearchTraces: Examples
Section titled “SearchTraces: Examples”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)),) {}SearchTracesHttp
Section titled “SearchTracesHttp”Source:
packages/digitalocean/src/Insights/SearchTracesHttp.tsKind: Layer · Provides:DigitalOcean.Insights.SearchTraces
SearchTraces over the Insights API.