com.azure.ai.metricsadvisor

Azure Metrics Advisor is a cloud-based service provided by Microsoft Azure that is designed to help organizations monitor and analyze metrics and time-series data from various sources. It is particularly focused on aiding in the detection of anomalies, trends, and patterns within this data, which can be invaluable for improving operational efficiency, identifying issues early, and making data-driven decisions.

Here are some key features and capabilities of Azure Metrics Advisor:

  • Anomaly Detection: Azure Metrics Advisor employs machine learning algorithms to automatically identify anomalies in time-series data. It can differentiate between normal variations and unusual patterns, helping organizations detect issues or opportunities for improvement.
  • Time-Series Data Ingestion: The service allows you to ingest time-series data from various sources, including Azure Monitor, Application Insights, IoT Hub, and custom data sources. This flexibility enables you to monitor a wide range of metrics.
  • Data Exploration: Users can explore their data, view historical trends, and gain insights into the behavior of various metrics over time. This can be useful for identifying seasonal patterns and understanding the normal behavior of your systems.
  • Integration with Azure Services: Azure Metrics Advisor integrates with other Azure services, such as Azure Monitor and Azure Data Explorer, making it part of a broader ecosystem for monitoring and analytics.
  • Alerts and Notifications: You can set up alerts and notifications based on detected anomalies or specific thresholds, ensuring that you are informed promptly when issues arise.

Getting Started

The Azure Metrics Advisor library provides advisor clients like MetricsAdvisorAsyncClient and MetricsAdvisorClient to connect to the Metrics Advisor Azure Cognitive Service to perform data monitoring. It also provides administration clients like MetricsAdvisorAdministrationClient and MetricsAdvisorAdministrationAsyncClient to build and manage models from custom documents.

Service clients are the point of interaction for developers to use Azure Form Recognizer. MetricsAdvisorClient is the synchronous service client and MetricsAdvisorAsyncClient is the asynchronous service client. The examples shown in this document use a credential object named DefaultAzureCredential for authentication, which is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the Azure Identity documentation".

Sample: Construct a MetricsAdvisorClient with DefaultAzureCredential

The following code sample demonstrates the creation of a MetricsAdvisorClient, using the `DefaultAzureCredentialBuilder` to configure it.

MetricsAdvisorClient metricsAdvisorClient =
     new MetricsAdvisorClientBuilder()
         .credential(new DefaultAzureCredentialBuilder().build())
         .endpoint("{endpoint}")
         .buildClient();

Further, see the code sample below to use MetricsAdvisorKeyCredential for client creation.

MetricsAdvisorClient metricsAdvisorClient =
     new MetricsAdvisorClientBuilder()
         .credential(new MetricsAdvisorKeyCredential("{subscription_key}", "{api_key}"))
         .endpoint("{endpoint}")
         .buildClient();

Let's take a look at the advisor client scenarios and their respective usage below.


Get the time series data from metric for you own ingested data

Sample: Given a metric list the time series data from a metricId

The following code sample demonstrates to get metric data time series information.

final OffsetDateTime startTime = OffsetDateTime.parse("2020-09-09T00:00:00Z");
 final OffsetDateTime endTime = OffsetDateTime.parse("2020-09-09T12:00:00Z");

 metricsAdvisorClient.listMetricSeriesData("metricId",
     Arrays.asList(new DimensionKey(new HashMap<String, String>() {{
             put("Dim1", "value1");
         }})), startTime, endTime)
     .forEach(metricSeriesData -> {
         System.out.println("List of data points for this series:");
         System.out.println(metricSeriesData.getMetricValues());
         System.out.println("Timestamps of the data related to this time series:");
         System.out.println(metricSeriesData.getTimestamps());
         System.out.printf("Series Key:");
         System.out.println(metricSeriesData.getSeriesKey().asMap());
     });

Note: For asynchronous sample, refer to AsyncListMetricSeriesData API.


Fetch the anomalies identified by an anomaly detection configuration

You can use the detected anomalies reflect actual anomalies in your data.

Sample: Query anomalies under anomaly detection configuration

The following code sample demonstrates how fetch all anomalies detected for a specific anomaly detection configuration.

final MetricWholeSeriesDetectionCondition wholeSeriesCondition = new MetricWholeSeriesDetectionCondition()
     .setConditionOperator(DetectionConditionOperator.OR)
     .setSmartDetectionCondition(new SmartDetectionCondition(
         50,
         AnomalyDetectorDirection.BOTH,
         new SuppressCondition(50, 50)))
     .setHardThresholdCondition(new HardThresholdCondition(
         AnomalyDetectorDirection.BOTH,
         new SuppressCondition(5, 5))
         .setLowerBound(0.0)
         .setUpperBound(100.0))
     .setChangeThresholdCondition(new ChangeThresholdCondition(
         50,
         30,
         true,
         AnomalyDetectorDirection.BOTH,
         new SuppressCondition(2, 2)));

 final String detectionConfigName = "my_detection_config";
 final String detectionConfigDescription = "anomaly detection config for metric";
 final AnomalyDetectionConfiguration detectionConfig
     = new AnomalyDetectionConfiguration(detectionConfigName)
     .setDescription(detectionConfigDescription)
     .setWholeSeriesDetectionCondition(wholeSeriesCondition);

 final String metricId = "0b836da8-10e6-46cd-8f4f-28262e113a62";
 Response<AnomalyDetectionConfiguration> response = metricsAdvisorAdminClient
     .createDetectionConfigWithResponse(metricId, detectionConfig, Context.NONE);
 System.out.printf("Response statusCode: %d%n", response.getStatusCode());
 AnomalyDetectionConfiguration createdDetectionConfig = response.getValue();
 System.out.printf("Detection config Id: %s%n", createdDetectionConfig.getId());
 System.out.printf("Name: %s%n", createdDetectionConfig.getName());
 System.out.printf("Description: %s%n", createdDetectionConfig.getDescription());
 System.out.printf("MetricId: %s%n", createdDetectionConfig.getMetricId());

Note: For asynchronous sample, refer to createDetectionConfigWithResponse(String metricId, AnomalyDetectionConfiguration detectionConfiguration) API.


List the root causes for an incident

Metrics Advisor will automatically group anomalies that share the same root cause into one incident. An incident usually indicates a real issue, Metrics Advisor performs analysis on top of it and provides automatic root cause analysis insights.

Sample: Find all the possible root causes for an incident

final String detectionConfigurationId = "c0dddf2539f-b804-4ab9-a70f-0da0c89c76d8";
 final String incidentId = "c5thh0f2539f-b804-4ab9-a70f-0da0c89c456d";

 metricsAdvisorClient.listIncidentRootCauses(detectionConfigurationId, incidentId)
     .forEach(incidentRootCause -> {
         System.out.printf("Description: %s%n", incidentRootCause.getDescription());
         System.out.printf("Series Key:");
         System.out.println(incidentRootCause.getSeriesKey().asMap());
         System.out.printf("Confidence for the detected incident root cause %.2f%n",
             incidentRootCause.getContributionScore());
     });

Note: For asynchronous sample, refer to listIncidentRootCauses(String detectionConfigurationId, String incidentId) API.

Classes

MetricsAdvisorAsyncClient

This class provides an asynchronous client to connect to the Metrics Advisor Azure Cognitive Service.

MetricsAdvisorClient

This class provides a synchronous client to connect to the Metrics Advisor Azure Cognitive Service.

MetricsAdvisorClientBuilder

This class provides a fluent builder API to help instantiation of MetricsAdvisorClient and MetricsAdvisorAsyncClient, call buildClient() buildClient} and buildAsyncClient() respectively to construct an instance of the desired client.

Enums

MetricsAdvisorServiceVersion

The versions of Azure Metrics Advisor supported by this client library.