Creating application insights with azure cli

Viewed 5382

I would like to create application insights using AZURE CLI. I can't find any documentation on this topic. Is it possible?

5 Answers

The az monitor app-insights component provide commands for creating, inspecting modifying, and deleting application insights components from the command line.

If you need to associate the generated instrumentation key with another resource, such as a function app, you can use grep and xargs as follows:

# Creates insights component for monitoring. Note generated instrumentation key
# is set in function app.
az resource create \
    --resource-group ${RESOURCE_GROUP_NAME} \
    --resource-type "Microsoft.Insights/components" \
    --name ${FUNCTION_APP_NAME} \
    --location ${LOCATION} \
    --properties '{"Application_Type":"web"}' \
| grep -Po "\"InstrumentationKey\": \K\".*\"" \
| xargs -I % az functionapp config appsettings set \
    --name ${FUNCTION_APP_NAME} \
    --resource-group ${RESOURCE_GROUP_NAME} \
    --settings "APPINSIGHTS_INSTRUMENTATIONKEY = %"

Use: az monitor app-insights component create

az monitor app-insights component create --app
                                         --location
                                         --resource-group
                                         [--application-type]
                                         [--ingestion-access {Disabled, Enabled}]
                                         [--kind]
                                         [--query-access {Disabled, Enabled}]
                                         [--retention-time]
                                         [--tags]
                                         [--workspace]

Application Insights is an extensible Application Performance Management (APM) service for web developers on multiple platforms. You can use it to monitor your live web application. You can get more details about Application Insights.

It belongs to the Azure Monitor. You can find appropriate CLI command from az monitor. Hope this will be helpful.

Related