internal async Task <AnomalyDetectionConfiguration> CreateMetricAnomalyDetectionConfiguration(MetricsAdvisorAdministrationClient adminClient)
        {
            DataFeed feed = await GetFirstDataFeed(adminClient).ConfigureAwait(false);

            AnomalyDetectionConfiguration config = PopulateMetricAnomalyDetectionConfiguration(feed.MetricIds.First());

            return(await adminClient.CreateMetricAnomalyDetectionConfigurationAsync(config).ConfigureAwait(false));
        }
Exemplo n.º 2
0
        internal async Task <MetricAnomalyDetectionConfiguration> CreateMetricAnomalyDetectionConfiguration(MetricsAdvisorAdministrationClient adminClient)
        {
            DataFeed feed = await GetFirstDataFeed(adminClient).ConfigureAwait(false);

            var config = new MetricAnomalyDetectionConfiguration(
                feed.MetricIds.First(),
                Recording.GenerateAlphaNumericId("Name"),
                new MetricAnomalyDetectionConditions(
                    DetectionConditionsOperator.And,
                    new SmartDetectionCondition(42, AnomalyDetectorDirection.Both, new SuppressCondition(1, 67)),
                    new HardThresholdCondition(23, 45, AnomalyDetectorDirection.Both, new SuppressCondition(1, 50)),
                    new ChangeThresholdCondition(12, 5, true, AnomalyDetectorDirection.Both, new SuppressCondition(1, 1))));

            return(await adminClient.CreateMetricAnomalyDetectionConfigurationAsync(config).ConfigureAwait(false));
        }
        public async Task CreateAndDeleteAnomalyDetectionConfigurationAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var adminClient = new MetricsAdvisorAdministrationClient(new Uri(endpoint), credential);

            string metricId = MetricId;

            #region Snippet:CreateAnomalyDetectionConfigurationAsync
            //@@ string metricId = "<metricId>";
            string configurationName = "Sample anomaly detection configuration";

            var hardThresholdSuppressCondition = new SuppressCondition(1, 100);
            var hardThresholdCondition         = new HardThresholdCondition(AnomalyDetectorDirection.Down, hardThresholdSuppressCondition)
            {
                LowerBound = 5.0
            };

            var smartDetectionSuppressCondition = new SuppressCondition(4, 50);
            var smartDetectionCondition         = new SmartDetectionCondition(10.0, AnomalyDetectorDirection.Up, smartDetectionSuppressCondition);

            var detectionCondition = new MetricWholeSeriesDetectionCondition()
            {
                HardThresholdCondition  = hardThresholdCondition,
                SmartDetectionCondition = smartDetectionCondition,
                CrossConditionsOperator = DetectionConditionsOperator.Or
            };

            var detectionConfiguration = new AnomalyDetectionConfiguration(metricId, configurationName, detectionCondition);

            Response <AnomalyDetectionConfiguration> response = await adminClient.CreateMetricAnomalyDetectionConfigurationAsync(detectionConfiguration);

            detectionConfiguration = response.Value;

            Console.WriteLine($"Anomaly detection configuration ID: {detectionConfiguration.Id}");
            #endregion

            // Delete the created anomaly detection configuration to clean up the Metrics Advisor resource.
            // Do not perform this step if you intend to keep using the configuration.

            await adminClient.DeleteMetricAnomalyDetectionConfigurationAsync(detectionConfiguration.Id);
        }