Skip to content

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.

us_eastuptime probe200timeouteu_westuptime probe200timeoutApiDownalert · down for 2memails ops@example.comApi stops answering2m laterus_eastuptime probe200timeouteu_westuptime probe200timeoutApiDownalert · down for 2memails ops@example.comApi stops answering2m later
Probes in several regions check the URL. The alert fires once the check has failed for its whole period, not on one bad probe.
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.

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.

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.

A sink sends a Kubernetes cluster’s logs to an OpenSearch endpoint. See Kubernetes.

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:

src/status.ts
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.

  • Droplet metrics need the monitoring agent: set monitoring: true on the Droplet.
  • App Platform has its own alerts on the App; see App Platform.