POST simple API metrics from the Azure API Gateway to a RESTful endpoint

RapidJames 1 Reputation point
2022-07-01T21:56:44.253+00:00

Can anyone inform me how I can get simple metrics for API calls from the Azure API Gateway and POST them to a RESTful endpoint as a simple JSON array? Like this:
{
"method": "get",
"status": 200,
"apiVersionName": "v1",
"apiId": "api_da1f42d3-c1a1-4e15-908c-d6ea93b2b0d1",
"endpoint": "/merchant-logs/v1/QZGY31G4BS71N1KTDQ",
"type": "http",
"timestamp": 1654093964000,
"originIP":"98.1.1.10"
}

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,294 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,401 Reputation points
    2022-07-06T18:59:06.93+00:00

    @RapidJames Thank you for reaching out to Microsoft Q&A. Sorry for the delay in response. I would like to split the question into 2 parts. First is to capture APIM gateway logs and second, to send it to a custom endpoint.

    Based on JSON format you described above; you were interested in capturing resource logs from APIM Gateway and check resource logs schema https://learn.microsoft.com/en-us/azure/api-management/gateway-log-schema-reference which provides info about all the fields logged. Resource logs (part of platform logs) are not collected until you configure it to route to any of the below destinations:

    218321-image.png

    So, you need to configure gateway logs to any of the destinations above (refer to docs: https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/diagnostic-settings?tabs=portal#create-diagnostic-settings for help in creating the docs) and resource logs will log JSON entry like below:

    218331-image.png

    (source: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-use-azure-monitor#view-diagnostic-data-in-azure-monitor)

    Second part: If you have already configured to send resource logs to any Azure resources or Azure Monitor partner solutions (https://learn.microsoft.com/en-us/azure/partner-solutions/overview) as above and looking for a solution to POST it to custom endpoint, then unfortunately you need to implement a custom solution to consume logs from that destination.

    For example, you can use Azure Functions to read from Log Analytics via API https://learn.microsoft.com/en-us/rest/api/loganalytics/dataaccess/query/get and POST it to RESTful endpoint. If you need more info on any of the above approaches, feel free to reach out. I am happy to help!

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.