surfacing metrics using MetricsQueryClient and LogsQueryClient


We can use application insights sdk specifically MetricsQueryClient to query storage account metrics or other metrics. By passing in the resourceId and metrics id, we would be able to pull out relevant metrics info. 


"/subscriptions/<tenant-id>/resourceGroups/<resource>>/providers/Microsoft.Storage/storageAccounts/your-storage-account";

var client = new MetricsQueryClient(new DefaultAzureCredential());

Response<MetricsQueryResult> results = await client.QueryResourceAsync(
    resourceId,
    new[] { "Availability", "Availability" }
);


In this example, I am using Managed Identity and setting it in the environment variabless.
These environment variables are:-

AZURE_CLIENT_ID and AZURE_TENANT_ID.


If the metrics are not valid or spell wrongly, then you will get error such as " 
Failed to find metric configuration for provider: Microsoft.Storage, 
resource Type: storageAccounts, metric: Transaction, Valid metrics: 
UsedCapacity,Transactions,Ingress,Egress,SuccessServerLatency,SuccessE2ELatency,Availability"







The sample code can be shown in example here :-

https://github.com/mitzenjeremywoo/app-insights-metricslogs






Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm