How to configure anomaly detector alert and query detection results in JAVA?

sukharev 61 Reputation points
2023-02-28T17:34:43.2+00:00

Anyone try to use Azure Anomaly Detector in JAVA? I understand Microsoft not provide a lot of support for JAVA but I have to do it. Typescript makes sense too but JAVA will be better.

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,241 questions
0 comments No comments
{count} votes

Accepted answer
  1. YutongTie-MSFT 53,931 Reputation points
    2023-02-28T23:36:46.01+00:00

    Hello sukharev

    Thanks for reaching out to us, there is Java SDK for Anomaly Detector - https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/metricsadvisor/azure-ai-metricsadvisor#key-concepts

    This example demonstrates how a user can configure an alerting configuration for detected anomalies in their data.

    String detectionConfigurationId1 = "9ol48er30-6e6e-4391-b78f-b00dfee1e6f5";
    String detectionConfigurationId2 = "3e58er30-6e6e-4391-b78f-b00dfee1e6f5";
    String hookId1 = "5f48er30-6e6e-4391-b78f-b00dfee1e6f5";
    String hookId2 = "8i48er30-6e6e-4391-b78f-b00dfee1e6f5";
    
    final AnomalyAlertConfiguration anomalyAlertConfiguration
        = metricsAdvisorAdminClient.createAlertConfig(
            new AnomalyAlertConfiguration("My anomaly alert config name")
                .setDescription("alert config description")
                .setMetricAlertConfigurations(
                    Arrays.asList(
                        new MetricAlertConfiguration(detectionConfigurationId1,
                            MetricAnomalyAlertScope.forWholeSeries()),
                        new MetricAlertConfiguration(detectionConfigurationId2,
                            MetricAnomalyAlertScope.forWholeSeries())
                            .setAlertConditions(new MetricAnomalyAlertConditions()
                                .setSeverityRangeCondition(new SeverityCondition(AnomalySeverity.HIGH,
                                    AnomalySeverity.HIGH)))
                    ))
                .setCrossMetricsOperator(MetricAlertConfigurationsOperator.AND)
                .setHookIdsToAlert(Arrays.asList(hookId1, hookId2)));
    
    

    Query anomaly detection results

    String alertConfigurationId = "9ol48er30-6e6e-4391-b78f-b00dfee1e6f5";
    final OffsetDateTime startTime = OffsetDateTime.parse("2020-01-01T00:00:00Z");
    final OffsetDateTime endTime = OffsetDateTime.parse("2020-09-09T00:00:00Z");
    metricsAdvisorClient.listAlerts(
        alertConfigurationId,
            startTime, endTime)
        .forEach(alert -> {
            System.out.printf("AnomalyAlert Id: %s%n", alert.getId());
            System.out.printf("AnomalyAlert created on: %s%n", alert.getCreatedTime());
    
            // List anomalies for returned alerts
            metricsAdvisorClient.listAnomaliesForAlert(
                alertConfigurationId,
                alert.getId())
                .forEach(anomaly -> {
                    System.out.printf("DataPoint Anomaly was created on: %s%n", anomaly.getCreatedTime());
                    System.out.printf("DataPoint Anomaly severity: %s%n", anomaly.getSeverity().toString());
                    System.out.printf("DataPoint Anomaly status: %s%n", anomaly.getStatus());
                    System.out.printf("DataPoint Anomaly related series key: %s%n", anomaly.getSeriesKey().asMap());
                });
        });
    
    

    I hope this helps, Please let me know if you need more help.

    Regards,

    Yutong

    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.