MetricsQueryClient.Query(String, IEnumerable<String>, MetricsQueryOptions, CancellationToken) Method

Definition

Queries metrics for a resource.

string resourceId =
    "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/Microsoft.OperationalInsights/workspaces/<workspace_name>";

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

Response<MetricQueryResult> results = await metricsClient.QueryAsync(
    resourceId,
    new[] {"Microsoft.OperationalInsights/workspaces"}
);

foreach (var metric in results.Value.Metrics)
{
    Console.WriteLine(metric.Name);
    foreach (var element in metric.TimeSeries)
    {
        Console.WriteLine("Dimensions: " + string.Join(",", element.Metadata));

        foreach (var metricValue in element.Data)
        {
            Console.WriteLine(metricValue);
        }
    }
}
public virtual Azure.Response<Azure.Monitor.Query.Models.MetricQueryResult> Query (string resourceId, System.Collections.Generic.IEnumerable<string> metrics, Azure.Monitor.Query.MetricsQueryOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member Query : string * seq<string> * Azure.Monitor.Query.MetricsQueryOptions * System.Threading.CancellationToken -> Azure.Response<Azure.Monitor.Query.Models.MetricQueryResult>
override this.Query : string * seq<string> * Azure.Monitor.Query.MetricsQueryOptions * System.Threading.CancellationToken -> Azure.Response<Azure.Monitor.Query.Models.MetricQueryResult>
Public Overridable Function Query (resourceId As String, metrics As IEnumerable(Of String), Optional options As MetricsQueryOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Response(Of MetricQueryResult)

Parameters

resourceId
System.String

The resource name. For example: /subscriptions/[subscription_id]/resourceGroups/[resource_group_name]/providers/Microsoft.OperationalInsights/workspaces/[workspace_name].

metrics
System.Collections.Generic.IEnumerable<System.String>

The list of metrics to query.

options
MetricsQueryOptions

The additional request options.

cancellationToken
System.Threading.CancellationToken

The System.Threading.CancellationToken to use.

Returns

Response<MetricQueryResult>

The MetricQueryResult instance containing the query results.

Applies to