I would like to create application insights using AZURE CLI. I can't find any documentation on this topic. Is it possible?
-
2Take a look here https://github.com/Azure/azure-cli/issues/5543#issuecomment-365001620 – Rohit Saigal Nov 15 '18 at 11:31
-
Seems nice, I will try it – Dzior Nov 15 '18 at 13:03
5 Answers
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

- 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
The az monitor app-insights component provide commands for creating, inspecting modifying, and deleting application insights components from the command line.

- 559
- 1
- 6
- 12
-
3But 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
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]

- 1,630
- 18
- 16
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 = %"

- 69
- 4
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.

- 29,862
- 2
- 22
- 39