Reputation: 395
I have a function app with a single, timer-triggered function running in MS Azure.
Background
*/15 * * * * *
Problem
Question
Upvotes: 3
Views: 2169
Reputation:
Here is the workaround I did to get the Metrics in Azure Function Portal Overview Tab and the alerts as per the required condition if met:
Firstly, I checked my Timer Trigger (*/15 * * * * *
) Azure Function App running successful in locally for every 15 seconds:
Configured the Azure Functions to Application Insights in Visual Studio and then Published to the Azure Portal Function App.
All the metrics, Function Execution Count, Memory working Set, Server Request Time, Server Response Times are recorded while running the Azure Function App Timer Trigger at every 15 seconds as you can see in the screenshot below:
what is the best practice for implementing an alert for a specific function on a timer trigger not firing as expected (or erroring)?
To create a Alert:
Step 1: Go to the Associated Application Insights Resource with the Function App > Select Alerts from Monitoring Section.
Step 2:
Click on Create Menu > Alert Rule > Type as Count in the Search Bar and Select the Metric named as <YourFunctionName> Count
After Selecting the Metric, Make your requirement condition to get alerts as you can see the screenshot below that I made alert rule to the condition for every 5 minutes if function count is below < 15 times.
After clicking on done, you will see like:
You'll get the alert rule creation successful notification in the notification bar:
Run the Function and check the Alerts Page from Monitoring Section in the Azure Application Insights Resource.
To get more details like Function execution count per minute and the timings, Click on the color bar as you can see the screenshot below when you clicked on it:
Reference: Monitor Via Application Insights - Alert Rules
Note:
my question of why for a function app I previous deployed, the "Function Execution Count" is always ever 0.
Please check few steps given below:
Make Sure You have configured the Application Insights while publishing the Function App as shown in 2nd Image.
In the Azure Portal Function App > Under Application Insights option, You have to see this kind of Message: Your app is connected to App Insights Resource: <yourFunctionName>
If that message not visible or you can cross check by doing like this:
Azure Portal > Function App > Application Insights under Settings > Select the option Change your Resource > Select Existing Resource > Select Your Subscription - Then all the function apps will be appeared in the table, select the deployed function app which you want to track the logs and metrics
.
AzureWebJobsStorage
and WEBSITE_CONTENTAZUREFILECONNECTION
are having same storage account connection string/values and the AppInsights Instrumentation Key
and its connection string
values verify by checking the Application Insights Resources associated with that function app.Before the workaround for Azure Functions Python Stack - Application Insights, there are some limitations:
Example: I Selected South India location where Consumption and Premium Hosting plans are not available for my Subscription or the selected Location. If I need for that location, I need to configure through AI SDK as shown below:
Here is the workaround I did to get the Metrics in Azure Function Portal Overview Tab and the alerts as per the required condition if met:
Firstly, I checked my Timer Trigger (*/15 * * * * *
) Azure Function App running successful in locally for every 15 seconds:
what is the best practice for implementing an alert for a specific function on a timer trigger not firing as expected (or erroring)?
To create a Alert:
Step 1: Go to the Associated Application Insights Resource with the Function App > Select Alerts from Monitoring Section.
Step 2:
Click on Create Menu > Alert Rule > Type as Count in the Search Bar and Select the Metric named as <YourFunctionName> Count
After Selecting the Metric, Make your requirement condition to get alerts as you can see the screenshot below that I made alert rule to the condition for every 5 minutes if function count is below < 15 times.
Run the Function and check the Alerts Page from Monitoring Section in the Azure Application Insights Resource.
Code used in Azure Functions Python Stack:
host.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
}
}
requirements.txt
azure-functions
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "<YourStorageAccountConnectionString",
"FUNCTIONS_WORKER_RUNTIME": "python"
}
}
init.py
import datetime
import logging
import azure.functions as func
def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
function.json:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "*/15 * * * * *"
}
]
}
Upvotes: 1