|
| 1 | +--- |
| 2 | +title: Monitoring Azure Functions |
| 3 | +description: Start here to learn how to monitor function apps running in Azure Functions using Azure Monitor |
| 4 | +ms.topic: how-to |
| 5 | +ms.service: azure-functions |
| 6 | +ms.custom: subject-monitoring |
| 7 | +ms.date: 07/05/2022 |
| 8 | +--- |
| 9 | + |
| 10 | +# Monitoring Azure Functions |
| 11 | + |
| 12 | +When you have critical applications and business processes relying on Azure resources, you want to monitor those resources for their availability, performance, and operation. |
| 13 | + |
| 14 | +This article describes the monitoring data generated by apps hosted in Azure Functions. Azure Functions uses [Azure Monitor](../azure-monitor/overview.md) to monitor the health of your function apps. If you're unfamiliar with the features of Azure Monitor common to all Azure services that use it, see [Monitoring Azure resources with Azure Monitor](../azure-monitor/essentials/monitor-azure-resource.md). |
| 15 | + |
| 16 | +Azure Functions uses Application Insights to collect and analyze log data from individual function executions in your function app. For more information, see [Monitor functions in Azure](functions-monitoring.md). |
| 17 | + |
| 18 | +## Monitoring data |
| 19 | + |
| 20 | +Azure Functions collects the same kinds of monitoring data as other Azure resources that are described in [Azure Monitor data collection](../azure-monitor/essentials/monitor-azure-resource.md#monitoring-data-from-azure-resources). |
| 21 | + |
| 22 | +See [Monitoring Azure Functions data reference](monitor-functions-reference.md) for detailed information on the metrics and logs metrics created by Azure Functions. |
| 23 | + |
| 24 | +## Collection and routing |
| 25 | + |
| 26 | +Platform metrics and the Activity log are collected and stored automatically, but can be routed to other locations by using a diagnostic setting. |
| 27 | + |
| 28 | +Resource Logs aren't collected and stored until you create a diagnostic setting and route them to one or more locations. |
| 29 | + |
| 30 | +See [Create diagnostic setting to collect platform logs and metrics in Azure](../azure-monitor/essentials/diagnostic-settings.md) for the detailed process for creating a diagnostic setting using the Azure portal, CLI, or PowerShell. When you create a diagnostic setting, you specify which categories of logs to collect. The categories for *Azure Functions* are listed in [Azure Functions monitoring data reference](monitor-functions-reference.md#resource-logs). |
| 31 | + |
| 32 | +The metrics and logs you can collect are discussed in the following sections. |
| 33 | + |
| 34 | +## Analyzing metrics |
| 35 | + |
| 36 | +You can analyze metrics for *Azure Functions* with metrics from other Azure services using metrics explorer by opening **Metrics** from the **Azure Monitor** menu. See [Getting started with Azure Metrics Explorer](../azure-monitor/essentials/metrics-getting-started.md) for details on using this tool. |
| 37 | + |
| 38 | +For a list of the platform metrics collected for Azure Functions, see [Monitoring *Azure Functions* data reference metrics](monitor-functions-reference.md#metrics). |
| 39 | + |
| 40 | +For reference, you can see a list of [all resource metrics supported in Azure Monitor](../azure-monitor/essentials/metrics-supported.md). |
| 41 | + |
| 42 | +The following examples use Monitor Metrics to help estimate the cost of running your function app on a Consumption plan. To learn more about estimating Consumption plan costs, see [Estimating Consumption plan costs](functions-consumption-costs.md). |
| 43 | + |
| 44 | +[!INCLUDE [functions-monitor-metrics-consumption](../../includes/functions-monitor-metrics-consumption.md)] |
| 45 | + |
| 46 | +## Analyzing logs |
| 47 | + |
| 48 | +Data in Azure Monitor Logs is stored in tables where each table has its own set of unique properties. |
| 49 | + |
| 50 | +All resource logs in Azure Monitor have the same fields followed by service-specific fields. The common schema is outlined in [Azure Monitor resource log schema](../azure-monitor/essentials/resource-logs-schema.md). |
| 51 | + |
| 52 | +The [Activity log](../azure-monitor/essentials/activity-log.md) is a type of platform log in Azure that provides insight into subscription-level events. You can view it independently or route it to Azure Monitor Logs, where you can do much more complex queries using Log Analytics. |
| 53 | + |
| 54 | +For a list of the types of resource logs collected for Azure Functions, see [Monitoring Azure Functions data reference](monitor-functions-reference.md#resource-logs) |
| 55 | + |
| 56 | +For a list of the tables used by Azure Monitor Logs and queryable by Log Analytics, see [Monitoring Azure Functions data reference](monitor-functions-reference.md#azure-monitor-logs-tables) |
| 57 | + |
| 58 | +### Sample Kusto queries |
| 59 | + |
| 60 | +> [!IMPORTANT] |
| 61 | +> When you select **Logs** from the Azure Functions menu, Log Analytics is opened with the query scope set to the current resource. This means that log queries will only include data from that resource. If you want to run a query that includes data from other resources or data from other Azure services, select **Logs** from the **Azure Monitor** menu. See [Log query scope and time range in Azure Monitor Log Analytics](../azure-monitor/logs/scope.md) for details. |
| 62 | +
|
| 63 | +Following are queries that you can use to help you monitor your Azure Function. |
| 64 | + |
| 65 | +The following sample query can help you monitor all your functions app logs: |
| 66 | + |
| 67 | +```Kusto |
| 68 | +FunctionAppLogs |
| 69 | +| project TimeGenerated, HostInstanceId, Message, _ResourceId |
| 70 | +| order by TimeGenerated desc |
| 71 | +``` |
| 72 | + |
| 73 | +The following sample query can help you monitor a specific functions app's logs: |
| 74 | + |
| 75 | +```Kusto |
| 76 | +FunctionAppLogs |
| 77 | +| where FunctionName == "<Function name>" |
| 78 | +| order by TimeGenerated desc |
| 79 | +``` |
| 80 | + |
| 81 | +The following sample query can help you monitor exceptions on a specific functions app's logs: |
| 82 | + |
| 83 | +```Kusto |
| 84 | +FunctionAppLogs |
| 85 | +| where ExceptionDetails != "" |
| 86 | +| where FunctionName == "<Function name>" |
| 87 | +| order by TimeGenerated desc |
| 88 | +``` |
| 89 | + |
| 90 | +## Alerts |
| 91 | + |
| 92 | +Azure Monitor alerts proactively notify you when important conditions are found in your monitoring data. They allow you to identify and address issues in your system before your customers notice them. You can set alerts on [metrics](../azure-monitor/alerts/alerts-metric-overview.md), [logs](../azure-monitor/alerts/alerts-unified-log.md), and the [activity log](../azure-monitor/alerts/activity-log-alerts.md). Different types of alerts have benefits and drawbacks. |
| 93 | + |
| 94 | +If you're creating or running an application that run on Functions [Azure Monitor Application Insights](../azure-monitor/overview.md#application-insights) may offer other types of alerts. |
| 95 | + |
| 96 | +The following table lists common and recommended alert rules for Functions. |
| 97 | + |
| 98 | +| Alert type | Condition | Examples | |
| 99 | +|:---|:---|:---| |
| 100 | +| Metric | Average connections| When number of connections exceed a set value| |
| 101 | +| Metric | HTTP 404| When HTTP 404 responses exceed a set value| |
| 102 | +| Metric | HTTP Server Errors| When HTTP 5xx errors exceed a set value| |
| 103 | +| Activity Log | Create or Update Web App | When app is created or updated| |
| 104 | +| Activity Log | Delete Web App | When app is deleted| |
| 105 | +| Activity Log | Restart Web App| When app is restarted| |
| 106 | +| Activity Log | Stop Web App| When app is stopped| |
| 107 | + |
| 108 | +## Next steps |
| 109 | + |
| 110 | +For more information about monitoring Azure Functions, see the following articles: |
| 111 | + |
| 112 | +* [Monitor Azure Functions](functions-monitoring.md) - details how-to monitor a function app. |
| 113 | +* [Monitoring Azure Functions data reference](monitor-functions-reference.md) - reference of the metrics, logs, and other important values created by your function app. |
| 114 | +* [Monitoring Azure resources with Azure Monitor](../azure-monitor/essentials/monitor-azure-resource.md) - details monitoring Azure resources. |
| 115 | +* [Analyze Azure Functions telemetry in Application Insights](analyze-telemetry-data.md) - details how-to view and query the data being collected from a function app. |
0 commit comments