Tutorial: Monitor published APIs

With Azure Monitor, you can visualize, query, route, archive, and take actions on the metrics or logs coming from your Azure API Management service.

In this tutorial, you learn how to:

  • View metrics of your API
  • Set up an alert rule
  • View activity logs
  • Enable and view resource logs

You can also use API Management's built-in analytics to monitor the usage and performance of your APIs.




This feature is available in the Premium, Standard, Basic, and Developer tiers of API Management.

View metrics of your APIs

API Management emits metrics every minute, giving you near real-time visibility into the state and health of your APIs. The following are the two most frequently used metrics. For a list of all available metrics, see supported metrics.

  • Capacity - helps you make decisions about upgrading/downgrading your APIM services. The metric is emitted per minute and reflects the gateway capacity at the time of reporting. The metric ranges from 0-100 calculated based on gateway resources such as CPU and memory utilization.
  • Requests - helps you analyze API traffic going through your API Management services. The metric is emitted per minute and reports the number of gateway requests with dimensions. Filter requests by response codes, location, hostname, and errors.


The following metrics have been deprecated as of May 2019 and will be retired in August 2023: Total Gateway Requests, Successful Gateway Requests, Unauthorized Gateway Requests, Failed Gateway Requests, Other Gateway Requests. Please migrate to the Requests metric which provides equivalent functionality.

Screenshot of Metrics in API Management Overview

To access metrics:

  1. In the Azure portal, navigate to your API Management instance. On the Overview page, review key metrics for your APIs.

  2. To investigate metrics in detail, select Metrics from the menu near the bottom of the page.

    Screenshot of Metrics item in Monitoring menu

  3. From the drop-down, select metrics you're interested in. For example, Requests.

  4. The chart shows the total number of API calls.

  5. You can filter the chart using the dimensions of the Requests metric. For example, select Add filter, select Backend Response Code Category, enter 500 as the value. The chart shows the number of requests failed in the API backend.

Set up an alert rule

You can receive alerts based on metrics and activity logs. Azure Monitor allows you to configure an alert to do the following when it triggers:

  • Send an email notification
  • Call a webhook
  • Invoke an Azure Logic App

To configure an example alert rule based on a request metric:

  1. In the Azure portal, navigate to your API Management instance.

  2. Select Alerts from the menu bar near the bottom of the page.

    Screenshot of Alerts option in Monitoring menu

  3. Select + New alert rule.

  4. In the Create alert rule window, Select condition.

  5. In the Configure signal logic window:

    1. In Signal type, select Metrics.
    2. In Signal name, select Requests.
    3. In Split by dimensions, in Dimension name, select Gateway Response Code Category.
    4. In Dimension values, select 4xx, for client errors such as unauthorized or invalid requests.
    5. In Alert logic, specify a Threshold value after which the alert should be triggered.
    6. In Evaluated based on, specify Aggregation granularity and Frequency of evaluation, then select Done.

    Screenshot of Configure Signal Logic windows

  6. Select an existing action group or create a new one. In the following example, a new action group is created. A notification email will be sent to admin@contoso.com.

    Screenshot of notifications for new action group

  7. Enter a name and description of the alert rule and select the severity level.

  8. Select Create alert rule.

  9. Now, test the alert rule by calling the Conference API without an API key. For example:

    curl GET https://apim-hello-world.azure-api.cn/conference/speakers HTTP/1.1 

    An alert triggers based on the evaluation period, and it will send email to admin@contoso.com.

    Alerts also appear on the Alerts page for the API Management instance.

    Screenshot of alerts in portal

Activity logs

Activity logs provide insight into the operations on your API Management services. Using activity logs, you can determine the "what, who, and when" for any write operations (PUT, POST, DELETE) taken on your API Management services.


Activity logs do not include read (GET) operations or operations performed in the Azure portal or using the original Management APIs.

You can access activity logs in your API Management service, or access logs of all your Azure resources in Azure Monitor.

Screenshot of activity log in portal

To view the activity log:

  1. In the Azure portal, navigate to your API Management instance.

  2. Select Activity log.

    Screenshot of Activity log item in Monitoring menu

  3. Select the desired filtering scope and then Apply.

Resource logs

Resource logs provide rich information about operations and errors that are important for auditing and troubleshooting purposes. Resource logs differ from activity logs. The activity log provides insights into the operations run on your Azure resources. Resource logs provide insight into operations that your resource ran.

To configure resource logs:

  1. In the Azure portal, navigate to your API Management instance.

  2. Select Diagnostic settings.

    Screenshot of Diagnostic settings item in Monitoring menu

  3. Select + Add diagnostic setting.

  4. Select the logs or metrics that you want to collect.

    You can archive resource logs along with metrics to a storage account, stream them to an Event Hub, or send them to a Log Analytics workspace.

For more information, see Create diagnostic settings to send platform logs and metrics to different destinations.

View diagnostic data in Azure Monitor

If you enable collection of GatewayLogs or metrics in a Log Analytics workspace, it can take a few minutes for data to appear in Azure Monitor. To view the data:

  1. In the Azure portal, navigate to your API Management instance.

  2. Select Logs from the menu near the bottom of the page.

    Screenshot of Logs item in Monitoring menu

Run queries to view the data. Several sample queries are provided, or run your own. For example, the following query retrieves the most recent 24 hours of data from the GatewayLogs table:

| where TimeGenerated > ago(1d) 

For more information about using resource logs for API Management, see:

The following JSON indicates a sample entry in GatewayLogs for a successful API request. For details, see the schema reference.

    "Level": 4,
    "isRequestSuccess": true,
    "time": "2020-10-14T17:xx:xx.xx",
    "operationName": "Microsoft.ApiManagement/GatewayLogs",
    "category": "GatewayLogs",
    "durationMs": 152,
    "callerIpAddress": "xx.xx.xxx.xx",
    "correlationId": "3f06647e-xxxx-xxxx-xxxx-530eb9f15261",
    "location": "China North",
    "properties": {
        "method": "GET",
        "url": "https://apim-hello-world.azure-api.cn/conference/speakers",
        "backendResponseCode": 200,
        "responseCode": 200,
        "responseSize": 41583,
        "cache": "none",
        "backendTime": 87,
        "requestSize": 526,
        "apiId": "demo-conference-api",
        "operationId": "GetSpeakers",
        "apimSubscriptionId": "master",
        "clientTime": 65,
        "clientProtocol": "HTTP/1.1",
        "backendProtocol": "HTTP/1.1",
        "apiRevision": "1",
        "clientTlsVersion": "1.2",
        "backendMethod": "GET",
        "backendUrl": "https://conferenceapi.chinacloudsites.cn/speakers"

Next steps

In this tutorial, you learned how to:

  • View metrics of your API
  • Set up an alert rule
  • View activity logs
  • Enable and view resource logs

Advance to the next tutorial: