Exemple #1
0
        public async Task GetAnomaliesForDetectionConfigurationWithMinimumSetup(bool useTokenCredential)
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);

            var options = new GetAnomaliesForDetectionConfigurationOptions(SamplingStartTime, SamplingEndTime);

            var anomalyCount = 0;

            await foreach (DataPointAnomaly anomaly in client.GetAnomaliesForDetectionConfigurationAsync(DetectionConfigurationId, options))
            {
                Assert.That(anomaly, Is.Not.Null);
                Assert.That(anomaly.DataFeedId, Is.Null);
                Assert.That(anomaly.MetricId, Is.Null);
                Assert.That(anomaly.DetectionConfigurationId, Is.Null);
                Assert.That(anomaly.CreatedOn, Is.Null);
                Assert.That(anomaly.LastModified, Is.Null);
                Assert.That(anomaly.Status, Is.Null);

                Assert.That(anomaly.Timestamp, Is.InRange(SamplingStartTime, SamplingEndTime));
                Assert.That(anomaly.Severity, Is.Not.EqualTo(default(AnomalySeverity)));

                ValidateSeriesKey(anomaly.SeriesKey);

                if (++anomalyCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(anomalyCount, Is.GreaterThan(0));
        }
Exemple #2
0
        public async Task GetAnomaliesForDetectionConfigurationWithOptionalFilter()
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            var options = new GetAnomaliesForDetectionConfigurationOptions(SamplingStartTime, SamplingEndTime)
            {
                Filter = new AnomalyFilter(AnomalySeverity.Medium, AnomalySeverity.Medium)
            };

            var dimensions = new Dictionary <string, string>()
            {
                { "city", "Delhi" }, { "category", "Handmade" }
            };
            var groupKey1 = new DimensionKey(dimensions);

            dimensions = new Dictionary <string, string>()
            {
                { "city", "Kolkata" }
            };
            var groupKey2 = new DimensionKey(dimensions);

            options.Filter.DimensionKeys.Add(groupKey1);
            options.Filter.DimensionKeys.Add(groupKey2);

            var anomalyCount = 0;

            await foreach (DataPointAnomaly anomaly in client.GetAnomaliesForDetectionConfigurationAsync(DetectionConfigurationId, options))
            {
                Assert.That(anomaly, Is.Not.Null);
                Assert.That(anomaly.DataFeedId, Is.Null);
                Assert.That(anomaly.MetricId, Is.Null);
                Assert.That(anomaly.DetectionConfigurationId, Is.Null);
                Assert.That(anomaly.CreatedOn, Is.Null);
                Assert.That(anomaly.LastModified, Is.Null);
                Assert.That(anomaly.Status, Is.Null);

                Assert.That(anomaly.Timestamp, Is.InRange(SamplingStartTime, SamplingEndTime));
                Assert.That(anomaly.Severity, Is.EqualTo(AnomalySeverity.Medium));

                ValidateSeriesKey(anomaly.SeriesKey);

                anomaly.SeriesKey.TryGetValue("city", out string city);
                anomaly.SeriesKey.TryGetValue("category", out string category);

                Assert.That((city == "Delhi" && category == "Handmade") || city == "Kolkata");

                if (++anomalyCount >= MaximumSamplesCount)
                {
                    break;
                }
            }

            Assert.That(anomalyCount, Is.GreaterThan(0));
        }
Exemple #3
0
        public async Task GetAnomaliesForDetectionConfigurationAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

            var client = new MetricsAdvisorClient(new Uri(endpoint), credential);

            string detectionConfigurationId = DetectionConfigurationId;

            var startTime = DateTimeOffset.Parse("2020-01-01T00:00:00Z");
            var endTime   = DateTimeOffset.UtcNow;
            var options   = new GetAnomaliesForDetectionConfigurationOptions(startTime, endTime)
            {
                MaxPageSize = 3
            };

            int anomalyCount = 0;

            await foreach (DataPointAnomaly anomaly in client.GetAnomaliesForDetectionConfigurationAsync(detectionConfigurationId, options))
            {
                Console.WriteLine($"Anomaly value: {anomaly.Value}");

                if (anomaly.ExpectedValue.HasValue)
                {
                    Console.WriteLine($"Anomaly expected value: {anomaly.ExpectedValue}");
                }

                Console.WriteLine($"Anomaly at timestamp: {anomaly.Timestamp}");
                Console.WriteLine($"Severity: {anomaly.Severity}");
                Console.WriteLine("Series key:");

                foreach (KeyValuePair <string, string> keyValuePair in anomaly.SeriesKey.AsDictionary())
                {
                    Console.WriteLine($"  Dimension '{keyValuePair.Key}': {keyValuePair.Value}");
                }

                Console.WriteLine();

                // Print at most 3 anomalies.
                if (++anomalyCount >= 3)
                {
                    break;
                }
            }
        }