Azure API Management

Monitoring & Alerts Setup for Azure API Management

Effective monitoring and proactive alerting are crucial for ensuring the health, performance, and availability of your Azure API Management instances. This guide walks you through setting up robust monitoring and alerting mechanisms.

Key Monitoring Metrics

Azure API Management exposes a rich set of metrics through Azure Monitor. Some of the most critical metrics to track include:

Setting Up Azure Monitor Alerts

Azure Monitor allows you to define alert rules that trigger actions when specific metric thresholds are breached. Follow these steps to configure alerts:

Step 1: Navigate to Azure Monitor

In the Azure portal, go to the API Management service you want to monitor. In the left-hand menu, under the Monitoring section, select Alerts.

Step 2: Create a New Alert Rule

Click on the + Create button and select Alert rule.

Step 3: Define the Condition

  • Scope: Ensure your API Management service is selected.
  • Condition Type: Select Metrics.
  • Signal Name: Choose the metric you want to monitor (e.g., 5xx errors, Total requests, Latency).
  • Alert Logic: Configure the Threshold (e.g., greater than, less than, equal to), Operator, and the Aggregation granularity (Period) and Frequency of evaluation. For example, to alert on high server errors, you might set: Metric = 5xx errors, Condition = Greater than, Threshold = 10, Period = 5 minutes, Frequency = 1 minute.

Consider setting alerts for:

  • High rates of 5xx errors (e.g., > 5 errors in 5 minutes).
  • Unusually high latency (e.g., average latency > 2 seconds for 5 minutes).
  • Sudden drops or spikes in request volume (indicating potential issues or unexpected usage).
  • Low cache hit rates (indicating potential performance bottlenecks).

Step 4: Define Actions

Under the Actions tab, you can define what happens when the alert fires. The most common action is to use Action Groups.

Action Group Options:

  • Email/SMS/Push/Voice: Send notifications to predefined contacts.
  • Webhooks: Integrate with external systems (e.g., PagerDuty, Slack).
  • Azure Functions: Trigger custom automation.
  • Logic Apps: Orchestrate complex workflows.
  • ITSM: Integrate with IT Service Management tools.

If you don't have an action group, click Create action group to set one up.

Step 5: Configure Alert Rule Details

Provide a descriptive Alert rule name (e.g., "APIM-High-5xx-Errors"), severity level, and a detailed description. You can also enable the rule immediately or save it as a draft.

Step 6: Review and Create

Review all your configurations and click Create to deploy the alert rule.

Using Log Analytics for Advanced Monitoring

For more in-depth analysis, troubleshooting, and custom alerting, consider sending your API Management diagnostic logs to a Log Analytics workspace:

  1. In your API Management service, navigate to Diagnostic settings.
  2. Click Add diagnostic setting.
  3. Select the log categories you want to collect (e.g., GatewayLogs, AuditLogs, OperationLogs, TraceLogs).
  4. Choose Send to Log Analytics workspace and select your workspace.
  5. Click Save.

Once logs are in Log Analytics, you can write Kusto Query Language (KQL) queries to analyze trends and create Log Alerts based on complex conditions derived from your logs.

Example KQL Query for High Latency:


traces
| where timestamp > ago(5m)
| where message startswith "Gateway processing"
| extend latency = toint(split(message, ' ')[6]) // Adjust index based on log format
| where latency > 2000 // Latency in ms
| summarize count() by bin(timestamp, 1m)
            

You can then use this query to create a Log Alert rule in Azure Monitor.

Best Practices

By implementing these monitoring and alerting strategies, you can maintain a healthy and performant API Management gateway, ensuring a seamless experience for your API consumers.

View API Management Metrics Configure Diagnostic Settings