This is an Azure Function that demonstrates how to pull metrics from an Application Insights instance via a series of queries, aggregate the specific values and store the results in blob storage.
- An Application Insights instance.
- An App Id and associated App Key for the application you are interested in aggregating data for.
- An Azure Storage account to store the function app.
- You will be prompted for this when deploying using the ARM template.
- An Azure Storage account for the aggregate data.
- You will be prompted for this when deploying using the ARM template.
- Clone the repo.
- Modify the config.js with your Application Insights App ID and App Key:
And the queries you want to run:
config.appInsights = { "endpoint": "https://api.applicationinsights.io/beta", "appId": "YOUR APP INSIGHTS APP ID", "key": "YOUR APP INSIGHTS KEY" };
config.queries = [ { "name": "TotalUserMsgs", "query": "customEvents | where name == 'MBFEvent.UserMessage' | project name | summarize count() by name" }, { "name": "TotalBotMsgs", "query": "customEvents | where name == 'MBFEvent.BotMessage' | project name | summarize count() by name" }, { "name": "MsgsPerUser", "query": "customEvents | extend userId = tostring(customDimensions [\"userId\"]) | project userId | summarize count() by userId" } ];
- Deploy to Azure using the Deploy to Azure button above:
- Set the storage account for the function app.
- Set the storage account for the aggregate data.
- Set the Git repo url for the cloned repo you want to deploy from.
- Set the branch from the cloned Git repo you wwant to deploy from.
- Add a new container in the blog storage account named aggregates.
- Add a new empty blob to the aggregates container named lastAggregation.json