MetricsQueryClient Class
- java.
lang. Object - com.
azure. monitor. query. MetricsQueryClient
- com.
public final 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 resourceUri, List<String> metricsNames) - Query metrics for an Azure resource. listMetricNamespaces(String resourceUri, OffsetDateTime startTime) - Lists all the metrics namespaces created for the resource URI. listMetricDefinitions(String resourceUri) - Lists all the metrics definitions created for the resource URI.
Method Summary
Methods inherited from java.lang.Object
Method Details
listMetricDefinitions
public PagedIterable
Lists all the metrics definitions created for the resource URI.
Parameters:
Returns:
listMetricDefinitions
public PagedIterable
Lists all the metrics definitions created for the resource URI.
Parameters:
Returns:
listMetricNamespaces
public PagedIterable
Lists all the metrics namespaces created for the resource URI.
Parameters:
Returns:
listMetricNamespaces
public PagedIterable
Lists all the metrics namespaces created for the resource URI.
Parameters:
Returns:
queryResource
public MetricsQueryResult queryResource(String resourceUri, List
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:
Returns:
queryResourceWithResponse
public Response
Returns all the Azure Monitor metrics requested for the resource.
Parameters:
Returns:
Applies to
Azure SDK for Java