How can i get Azure metrics using the az command in Powershell? - azure

How can i get the Azure metrics , failed requests , app performance, CPU usage and Memory usage ?
There is the az monitor metrics list --resource
[--aggregation {Average, Count, Maximum, Minimum, None, Total}]
[--dimension]
[--end-time]
[--filter]
[--interval]
[--metadata]
[--metrics]
[--namespace]
[--offset]
[--orderby]
[--resource-group]
[--resource-namespace]
[--resource-parent]
[--resource-type]
[--start-t
I have tried to use t as follows
az monitor metrics list --resource "AppServiceName"
but get and error:
az : usage error: --resource ID | --resource NAME --resource-group NAME --resource-type
TYPE [--resource-parent PARENT] [--resource-namespace NAMESPACE]

Old now - but the resource ID required takes a few forms for example
/subscriptions/b6ff2c43-9c91-4c25-bf05-62fdea862e7b/resourceGroups/My-RSG/providers/Microsoft.Web/serverfarms/mywhatever.
This is found in the properties seciton of the portal for example.
you can then run in azure cli
az monitor metrics list --resource /subscriptions/b6ff2c43-9c91-4c25-bf05-62fdea862e7b/resourceGroups/My-RSG/providers/Microsoft.Web/serverfarms/mywhatever.

Related

Unable to create Azure search service through terraform and AZ CLI with Standard3 High density SKU but getting the error

I am trying to create an azure search service through terraform but it is not supported through standard3 High Density SKU. Subsequently, I am trying to create it with AZ CLI but getting the error as"ERROR: Unrecognized arguments: --hosting-mode highDensity". How to resolve this error and create a search service with S3HD SKU?
I Passed the AZ CLI command to create an Azure Search Service with S3HD Sku but it failed saying hosting mode is an unsupported argument, Also terraform does not support High Density SKU.
I Tried to reproduce the same in my environment to create an Azure Search Service with S3HD SKU Azure CLI:
Follow the below steps to create Azure Search Service using CLI.
If you select Azure Search Service SKU S3HD, it will show as Standard3 High density as below.
Azure CLI Commands
#Sing into Azure Subscription
az login
#Create Azure Search service with SKU S3HD
az search service create --name venkatsearch --resource-group myResourceGroup --sku Standard3 --hosting-mode highDensity
Result:
az search service list --resource-group myResourceGroup
Result:
Once ran the above commands Azure Search Service with S3HD SKU are created successfully as below.
Refer the Ms Doc more about Azure Search Service using CLI.

How to access Azure resources through powershell?

Just want to know how can I get the service buses in the portal through powershell
I was able to access the app insights through this piece of script
az monitor app-insights component show | ConvertFrom-Json
Now I wish to access the service bus , app service and app service plans as well through powershell
I was using this
az monitor servicebus component show | ConvertFrom-Json
for service bus but it is not working.
You are using Azure CLI there, not the PowerShell modules.
If you want to list / show the details around the following services, then you need to use the corresponding Azure CLI commands:
ServiceBus
az servicebus namespace show --resource-group myresourcegroup --name mynamespace
Reference: https://learn.microsoft.com/en-us/cli/azure/servicebus/namespace?view=azure-cli-latest#az-servicebus-namespace-show
App Service
az webapp show --name MyWebapp --resource-group MyResourceGroup
Reference: https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az-webapp-show
App Service Plans
az appservice plan show --name MyAppServicePlan --resource-group MyResourceGroup
Reference: https://learn.microsoft.com/en-us/cli/azure/appservice/plan?view=azure-cli-latest#az-appservice-plan-show
Here is the full CLI reference: https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest
To get service bus namespace list in your current subscription, you use below command:
az servicebus namespace list
To get the service bus queue list you below command:
az servicebus queue list --resource-group myresourcegroup --namespace-name mynamespace
If you want for topic, keep topic in place of queue in above command.
If you want to get app service plans use the below command:
az appservice plan list
Alternatively, you can use azure resource graph query like below for servicebus:
resources
| where type =~ 'microsoft.servicebus/namespaces'
You can use azure resource graph query like below to get app services:
resources
| where type == 'microsoft.web/sites'
References taken from:
https://learn.microsoft.com/en-us/cli/azure/appservice/plan?view=azure-cli-latest#az-appservice-plan-list
https://learn.microsoft.com/en-us/cli/azure/servicebus?view=azure-cli-latest
Edit:
Yes if you want apim use below query:
resources
| where type == "microsoft.apimanagement/service"
Get apim Using cli :
az account set -s "Subscription name"
$Resources = az resource list
$Resources | Where type -in "Microsoft.ApiManagement/service"

Is there an Azure CLI command for getting Health Check status from Function App?

I've created a Function App, and everything seems to be running fine. In the Azure Portal, Function App Overview I can see that the Health Check is "100.00% (Healthy 2 / Degraded 0)", and on the Health Check page of the Function App I can see that it's enabled and the endpoint is "api/health".
Is there a way to get the "100% (Healthy 2 / Degraded 0)" through an Azure CLI command. It looks like az functionapp list only gives me the siteConfig.healthCheckPath value and that's not what I need.
You can fetch the values of Health Check Status metric by using the Azure CLI command az monitor metrics list as described here https://learn.microsoft.com/en-us/cli/azure/monitor/metrics?view=azure-cli-latest#az-monitor-metrics-list.
Example:
az monitor metrics list --resource myresource --resource-group myresourcegroup --resource-type "Microsoft.Web/sites" --metric "HealthCheckStatus" --interval 5m
Note that the --interval property is important as health checks do not support the default 1m interval used by az monitor metrics list

AZ command to fetch Azure Monitor logs

I have to fetch logs using AZ commands:
If I add a filter on Resource Group, it is not giving result.
For e.g.--
Following commands is working fine:
az monitor activity-log list --subscription "subscription1"
In the result I am getting logs for ResourceGroup1.
But when I execute following:
az monitor activity-log list --resource-group "ResourceGroup1"
It is giving 0 result.
I am using "azure-cli": "2.26.1"
You can use the below command to read monitor activity logs at resource group level
az monitor activity-log list -g "resource-group"
Here is the command to pull activity monitor logs with filters
az monitor activity-log list -g 'resource-group' --start-time 2021-07-29T12:00:00 --select {ResourceGroupName,EventTimestamp,CorrelationId,ResourceId} -o table
When we do AZ login, there is one field "isDefault": true for only one subscription (Default subscription of your account). For other Subscriptions, it will be False.
You will get results for all RGs under default Subscription. For other RGs, it will give 0 result.
Therefore, when you apply filter on a RG, you need to confirm that it's corresponding Subscription should be set as default. You can set same as:
az account set -s <subscription ID>

how to get the list of diagnostic settings for app services using az cli

I am trying to get list of web apps using az cli az webapp list. And when I try to get the diagnostic setting for the particular web app using az monitor diagnostic-settings list --resource-group nameRG --resource id. I dont get any information and logs and diagnostic settings are enabled for app services. I am not sure what i am doing wrong.
I am just trying to get the list of diagnostic settings for a resource. If you know better way please mention it.
Thanks
Usage:
az monitor diagnostic-settings list --resource Name --resource-group RGName --resource-type Microsoft.Web/sites
Or:
az monitor diagnostic-settings list --resource ID
Make sure the resource id correct like this format:
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
You could get the resource id by this command:
az webapp show --name MyWebapp --resource-group MyResourceGroup

Resources