Udostępnij za pośrednictwem


MetricsQueryClient Class

Definition

The MetricsQueryClient allows you to query the Azure Monitor Metrics service for a single Azure resource.

public class MetricsQueryClient
type MetricsQueryClient = class
Public Class MetricsQueryClient
Inheritance
MetricsQueryClient

Constructors

MetricsQueryClient()

Creates an instance of MetricsQueryClient to support mocking.

MetricsQueryClient(TokenCredential, MetricsQueryClientOptions)

Creates an instance of MetricsQueryClient for Azure Public Cloud usage. Uses the default 'https://management.azure.com' endpoint, unless Audience is set to an Azure sovereign cloud.

MetricsQueryClient(TokenCredential)

Creates an instance of MetricsQueryClient for Azure Public Cloud usage. Uses the default 'https://management.azure.com' endpoint. To access an Azure sovereign cloud, use the following constructor overload: MetricsQueryClient(TokenCredential, MetricsQueryClientOptions)

var client = new MetricsQueryClient(new DefaultAzureCredential());
MetricsQueryClient(Uri, TokenCredential, MetricsQueryClientOptions)

Creates an instance of MetricsQueryClient for the Azure cloud represented by endpoint.

Properties

Endpoint

Gets the endpoint used by the client.

Methods

GetMetricDefinitions(String, String, CancellationToken)

Gets metric definitions for a particular resource and metric namespace.

GetMetricDefinitionsAsync(String, String, CancellationToken)

Gets metric definitions for a particular resource and metric namespace.

GetMetricNamespaces(String, CancellationToken)

Gets metric namespaces for a particular resource.

GetMetricNamespacesAsync(String, CancellationToken)

Gets metric namespaces for a particular resource.

QueryResource(String, IEnumerable<String>, MetricsQueryOptions, CancellationToken)

Queries metrics for a resource.

string resourceId =
    "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/<resource_provider>/<resource>";
var client = new MetricsQueryClient(new DefaultAzureCredential());

Response<MetricsQueryResult> results = await client.QueryResourceAsync(
    resourceId,
    new[] { "Average_% Free Space", "Average_% Used Space" }
);

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

        foreach (MetricValue value in element.Values)
        {
            Console.WriteLine(value);
        }
    }
}
QueryResourceAsync(String, IEnumerable<String>, MetricsQueryOptions, CancellationToken)

Queries metrics for a resource.

string resourceId =
    "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/<resource_provider>/<resource>";
var client = new MetricsQueryClient(new DefaultAzureCredential());

Response<MetricsQueryResult> results = await client.QueryResourceAsync(
    resourceId,
    new[] { "Average_% Free Space", "Average_% Used Space" }
);

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

        foreach (MetricValue value in element.Values)
        {
            Console.WriteLine(value);
        }
    }
}

Applies to