Monitoring and Insights
DigitalOcean watches your resources in two ways. Monitoring collects metrics from Droplets, runs uptime checks against your URLs from several regions, and alerts when a check fails or a metric crosses a line. Insights stores metrics, logs and traces for every kind of resource, and its alert rules notify a notification channel: an email address, a Slack channel or a webhook.
Check a URL
Section titled “Check a URL”const check = yield* DigitalOcean.Monitoring.UptimeCheck("Api", { type: "https", target: api.url, regions: ["us_east", "eu_west"],});yield* DigitalOcean.Monitoring.UptimeAlert("ApiDown", { checkId: check.checkId, type: "down", period: "2m", notifications: { email: ["ops@example.com"] },});type: "latency" with a threshold in milliseconds alerts on slow answers, and "ssl_expiry" before a certificate expires. Alert emails must be verified on the team.
Alert on Droplet metrics
Section titled “Alert on Droplet metrics”yield* DigitalOcean.Monitoring.AlertPolicy("HighCpu", { type: "v1/insights/droplet/cpu", description: "CPU above 80% for 5 minutes", compare: "GreaterThan", value: 80, window: "5m", tags: ["web"], email: ["ops@example.com"],});A policy covers the Droplets in entities, or every Droplet with one of its tags.
Alert with Insights
Section titled “Alert with Insights”Insights alert rules cover any resource’s metrics and notify a channel:
const oncall = yield* DigitalOcean.Insights.NotificationChannel("OnCall", { email: { to: "oncall@example.com" },});yield* DigitalOcean.Insights.AlertRule("HighCpu", { metric: "do.droplets.cpu_utilization", resourceUrns: [host.urn], thresholds: { operator: "THRESHOLD_OPERATOR_GREATER_THAN", warning: 80, critical: 95 }, notify: [{ channelId: oncall.channelId }],});A channel can be slack with a webhook URL, or webhook to POST alerts as JSON. Insights.Dashboard declares a dashboard from its JSON definition.
Forward Kubernetes logs
Section titled “Forward Kubernetes logs”A sink sends a Kubernetes cluster’s logs to an OpenSearch endpoint. See Kubernetes.
Query metrics and logs
Section titled “Query metrics and logs”From a runtime, QueryMetrics, QueryMetricsRange, SearchLogs, SearchTraces and SearchSpans read Insights. They take a token with the insights:read scope, which reaches the runtime as a secret:
import * as DigitalOcean from "@alchemy.run/digitalocean";import * as Config from "effect/Config";import * as Effect from "effect/Effect";import * as HttpServerResponse from "effect/http/HttpServerResponse";
export default class Status extends DigitalOcean.App<Status>()( "Status", { 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: "do.droplets.cpu_utilization" }); return yield* HttpServerResponse.json(result.data); }).pipe(Effect.orDie), }; }).pipe(Effect.provide(DigitalOcean.Insights.QueryMetricsHttp)),) {}Queries are PromQL, against one region’s metrics.
Limits
Section titled “Limits”- Droplet metrics need the monitoring agent: set
monitoring: trueon the Droplet. - App Platform has its own alerts on the App; see App Platform.