Class MetricsQueryClient
The synchronous client for querying Azure Monitor metrics.
Azure Monitor Metrics is a feature of Azure Monitor that collects numeric data from monitored resources into a time-series database. Metrics are numerical values that are collected at regular intervals and describe some aspect of a system at a particular time. The MetricsQueryClient provides synchronous implementations of methods that query metrics from your Azure services.
Getting Started
Authenticating and building MetricsQueryClient instances are done through MetricsQueryClientBuilder.
The following sample shows how to build a new MetricsQueryClient instance.
MetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder()
.credential(tokenCredential)
.buildClient();
For more information on building and authenticating, see the MetricsQueryClientBuilder documentation.
Client Usage
For more information on using the MetricsQueryClient, see the following method documentation:
-
queryResource(String, List)- Query metrics for an Azure resource.listMetricNamespaces(String, OffsetDateTime)- Lists all the metrics namespaces created for the resource URI.listMetricDefinitions(String)- Lists all the metrics definitions created for the resource URI.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncom.azure.core.http.rest.PagedIterable<MetricDefinition> listMetricDefinitions(String resourceUri) Lists all the metrics definitions created for the resource URI.com.azure.core.http.rest.PagedIterable<MetricDefinition> listMetricDefinitions(String resourceUri, String metricsNamespace, com.azure.core.util.Context context) Lists all the metrics definitions created for the resource URI.com.azure.core.http.rest.PagedIterable<MetricNamespace> listMetricNamespaces(String resourceUri, OffsetDateTime startTime) Lists all the metrics namespaces created for the resource URI.com.azure.core.http.rest.PagedIterable<MetricNamespace> listMetricNamespaces(String resourceUri, OffsetDateTime startTime, com.azure.core.util.Context context) Lists all the metrics namespaces created for the resource URI.queryResource(String resourceUri, List<String> metricsNames) Returns all the Azure Monitor metrics requested for the resource.com.azure.core.http.rest.Response<MetricsQueryResult> queryResourceWithResponse(String resourceUri, List<String> metricsNames, MetricsQueryOptions options, com.azure.core.util.Context context) Returns all the Azure Monitor metrics requested for the resource.
-
Method Details
-
queryResource
Returns all the Azure Monitor metrics requested for the resource.Query metrics for an Azure resource
MetricsQueryResult response = metricsQueryClient.queryResource("{resource-id}", Arrays.asList("{metric-1}", "{metric-2}")); for (MetricResult metricResult : response.getMetrics()) { System.out.println("Metric name " + metricResult.getMetricName()); metricResult.getTimeSeries().stream() .flatMap(timeSeriesElement -> timeSeriesElement.getValues().stream()) .forEach(metricValue -> System.out.println("Time stamp: " + metricValue.getTimeStamp() + "; Total: " + metricValue.getTotal())); }- Parameters:
resourceUri- The resource URI for which the metrics is requested.metricsNames- The names of the metrics to query.- Returns:
- A time-series metrics result for the requested metric names.
- Throws:
NullPointerException- ifresourceUriis null.
-
queryResourceWithResponse
public com.azure.core.http.rest.Response<MetricsQueryResult> queryResourceWithResponse(String resourceUri, List<String> metricsNames, MetricsQueryOptions options, com.azure.core.util.Context context) Returns all the Azure Monitor metrics requested for the resource.- Parameters:
resourceUri- The resource URI for which the metrics is requested.metricsNames- The names of the metrics to query.options- Options to filter the query.context- Additional context that is passed through the Http pipeline during the service call. If no additional context is required, passContext.NONEinstead.- Returns:
- A time-series metrics result for the requested metric names.
- Throws:
NullPointerException- ifresourceUriis null.
-
listMetricNamespaces
public com.azure.core.http.rest.PagedIterable<MetricNamespace> listMetricNamespaces(String resourceUri, OffsetDateTime startTime) Lists all the metrics namespaces created for the resource URI.- Parameters:
resourceUri- The resource URI for which the metrics namespaces are listed.startTime- The returned list of metrics namespaces are created after the specified start time.- Returns:
- A
paged collectionof metrics namespaces. - Throws:
NullPointerException- ifresourceUriis null.
-
listMetricNamespaces
public com.azure.core.http.rest.PagedIterable<MetricNamespace> listMetricNamespaces(String resourceUri, OffsetDateTime startTime, com.azure.core.util.Context context) Lists all the metrics namespaces created for the resource URI.- Parameters:
resourceUri- The resource URI for which the metrics namespaces are listed.startTime- The returned list of metrics namespaces are created after the specified start time.context- Additional context that is passed through the Http pipeline during the service call. If no additional context is required, passContext.NONEinstead.- Returns:
- A
paged collectionof metrics namespaces. - Throws:
NullPointerException- ifresourceUriis null.
-
listMetricDefinitions
public com.azure.core.http.rest.PagedIterable<MetricDefinition> listMetricDefinitions(String resourceUri) Lists all the metrics definitions created for the resource URI.- Parameters:
resourceUri- The resource URI for which the metrics definitions are listed.- Returns:
- A
paged collectionof metrics definitions. - Throws:
NullPointerException- ifresourceUriis null.
-
listMetricDefinitions
public com.azure.core.http.rest.PagedIterable<MetricDefinition> listMetricDefinitions(String resourceUri, String metricsNamespace, com.azure.core.util.Context context) Lists all the metrics definitions created for the resource URI.- Parameters:
resourceUri- The resource URI for which the metrics definitions are listed.metricsNamespace- The metrics namespace to which the listed metrics definitions belong.context- Additional context that is passed through the Http pipeline during the service call. If no additional context is required, passContext.NONEinstead.- Returns:
- A
paged collectionof metrics definitions. - Throws:
NullPointerException- ifresourceUriis null.
-