Class MetricsQueryClient

java.lang.Object
com.azure.monitor.query.MetricsQueryClient

public final class MetricsQueryClient extends Object
The synchronous client for querying Azure Monitor metrics.

Instantiating a synchronous Metrics query Client

 MetricsQueryClient metricsQueryClient = new MetricsQueryClientBuilder()
         .credential(tokenCredential)
         .buildClient();
 
  • Method Details

    • queryResource

      public MetricsQueryResult queryResource(String resourceUri, List<String> metricsNames)
      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.
    • queryResourceWithResponse

      public Response<MetricsQueryResult> queryResourceWithResponse(String resourceUri, List<String> metricsNames, MetricsQueryOptions options, 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, pass Context.NONE instead.
      Returns:
      A time-series metrics result for the requested metric names.
    • listMetricNamespaces

      public 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 collection of metrics namespaces.
    • listMetricNamespaces

      public PagedIterable<MetricNamespace> listMetricNamespaces(String resourceUri, OffsetDateTime startTime, 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, pass Context.NONE instead.
      Returns:
      A paged collection of metrics namespaces.
    • listMetricDefinitions

      public 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 collection of metrics definitions.
    • listMetricDefinitions

      public PagedIterable<MetricDefinition> listMetricDefinitions(String resourceUri, String metricsNamespace, 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, pass Context.NONE instead.
      Returns:
      A paged collection of metrics definitions.