Home / OCI

OCIHow-toBeginner

Setting up OCI Monitoring alarms with email and Slack notifications

Create a Notifications topic, write MQL alarm queries for CPU, memory, load balancers and databases, and avoid the common no-data and noisy-alarm problems.

Deepak Bhardwaj2 min read

Applies toOCI Monitoring, Notifications, Compute Instance Monitoring plugin

1. Create a topic and subscriptions

TOPIC=$(oci ons topic create --compartment-id $C --name ops-critical --query 'data."topic-id"' --raw-output)
oci ons subscription create --compartment-id $C --topic-id $TOPIC --protocol EMAIL --subscription-endpoint oncall@contoso.com
oci ons subscription create --compartment-id $C --topic-id $TOPIC --protocol SLACK --subscription-endpoint https://hooks.slack.com/services/XXX/YYY/ZZZ

Email subscriptions must be confirmed from the email before they receive anything. Other supported protocols include HTTPS (custom webhooks), PagerDuty, SMS and Functions.

2. Write the alarm query (MQL)

MQL format: MetricName[interval]{dimension filters}.statistic() <condition>

Alarm Namespace Query
High CPU oci_computeagent CpuUtilization[5m].mean() > 85
High memory oci_computeagent MemoryUtilization[5m].mean() > 90
Instance down (no data) oci_computeagent CpuUtilization[1m].absent()
LB unhealthy backends oci_lbaas UnHealthyBackendServers[1m].max() > 0
Autonomous DB CPU oci_autonomous_database CpuUtilization[5m].mean() > 80
Object Storage 5xx errors oci_objectstorage ServerErrors[5m].sum() > 10
oci monitoring alarm create --compartment-id $C --metric-compartment-id $C \
  --display-name "prod-vm-cpu-high" --namespace oci_computeagent \
  --query-text 'CpuUtilization[5m]{resourceDisplayName =~ "prod-*"}.mean() > 85' \
  --severity CRITICAL --destinations "[\"$TOPIC\"]" --is-enabled true \
  --pending-duration PT5M --body "CPU above 85% for 5 minutes. Runbook: https://wiki/runbooks/cpu"

3. Avoid noise

  • Use --pending-duration (for example 5 minutes) so a short spike doesn't page anyone.
  • Set repeat notification only for critical alarms.
  • Use dimension filters to scope alarms, and split notifications per resource so one alarm covers a fleet but each VM fires separately.
  • Put the runbook link in --body.

4. "No data" problems

  • The Compute Instance Monitoring plugin must be enabled in the Oracle Cloud Agent, and the instance needs to reach the monitoring endpoint (a service gateway in private subnets).
  • Custom images may not have the Oracle Cloud Agent installed.
  • Check the metric exists in Metrics Explorer before you build the alarm on it.
oci monitoring metric list --compartment-id $C --namespace oci_computeagent --query 'data[].name' | sort -u

Tip

Filesystem usage isn't in the default compute metrics. Publish it as a custom metric (oci monitoring metric-data post) from a small cron script, or collect it with the Management Agent or your existing monitoring tool.