13

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

Dzior
  • 1,485
  • 1
  • 14
  • 30

5 Answers5

15

The link provided by Rohit works

az resource create \
    --resource-group $RESOURCE_GROUP \
    --resource-type "Microsoft.Insights/components" \
    --name $NAMESPACE_PREFIX-appinsights \
    --location $PRIMARY_LOCATION \
    --properties '{"Application_Type":"web"}'

https://github.com/Azure/azure-cli/issues/5543#issuecomment-365001620

Dzior
  • 1,485
  • 1
  • 14
  • 30
  • Does not work on Windows: `Error parsing JSON. '{Application_Type:web}' `. The fix is `--properties "{\"Application_Type\":\"web\"}"` – UserControl Jul 29 '20 at 11:41
5

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

Yngvar Johnsen
  • 559
  • 1
  • 6
  • 12
  • 3
    But don't forgot to install the AZ/CLI extensions with `az extension add --name application-insights` or the sub-command won't be available. – gsscoder Sep 15 '20 at 14:29
3

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]
genegc
  • 1,630
  • 18
  • 16
2

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 = %"
0

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.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39