コード例 #1
0
        public async Task GetMetricSeriesDefinitions(bool populateOptionalMembers)
        {
            var cityFilter = new List <string>()
            {
                "Belo Horizonte", "Los Angeles", "Osaka"
            };
            var categoryFilter = new List <string>()
            {
                "__SUM__", "Shoes Handbags & Sunglasses"
            };

            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            var options = new GetMetricSeriesDefinitionsOptions(SamplingStartTime);

            if (populateOptionalMembers)
            {
                options.DimensionCombinationsToFilter.Add("city", cityFilter);
                options.DimensionCombinationsToFilter.Add("category", categoryFilter);
            }

            var definitionCount = 0;

            await foreach (MetricSeriesDefinition definition in client.GetMetricSeriesDefinitionsAsync(MetricId, options))
            {
                Assert.That(definition, Is.Not.Null);
                Assert.That(definition.MetricId, Is.EqualTo(MetricId));

                ValidateDimensionKey(definition.SeriesKey);

                if (populateOptionalMembers)
                {
                    Dictionary <string, string> dimensionColumns = definition.SeriesKey.AsDictionary();

                    string city     = dimensionColumns["city"];
                    string category = dimensionColumns["category"];

                    Assert.That(cityFilter.Contains(city));
                    Assert.That(categoryFilter.Contains(category));
                }

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

            Assert.That(definitionCount, Is.GreaterThan(0));
        }
コード例 #2
0
        public async Task GetMetricSeriesDefinitionsWithOptionalDimensionFilter()
        {
            var cityFilter = new List <string>()
            {
                "Belo Horizonte", "Chennai", "Hong Kong"
            };
            var categoryFilter = new List <string>()
            {
                "__SUM__", "Outdoors"
            };

            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            var options = new GetMetricSeriesDefinitionsOptions(SamplingStartTime);

            options.DimensionCombinationsFilter.Add("city", cityFilter);
            options.DimensionCombinationsFilter.Add("category", categoryFilter);

            var definitionCount = 0;

            await foreach (MetricSeriesDefinition definition in client.GetMetricSeriesDefinitionsAsync(MetricId, options))
            {
                Assert.That(definition, Is.Not.Null);
                Assert.That(definition.MetricId, Is.EqualTo(MetricId));

                ValidateSeriesKey(definition.SeriesKey);

                DimensionKey seriesKey = definition.SeriesKey;

                Assert.That(seriesKey.TryGetValue("city", out string city));
                Assert.That(seriesKey.TryGetValue("category", out string category));

                Assert.That(cityFilter.Contains(city));
                Assert.That(categoryFilter.Contains(category));

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

            Assert.That(definitionCount, Is.GreaterThan(0));
        }
コード例 #3
0
        public async Task GetMetricSeriesDefinitionsWithOptionalDimensionFilter()
        {
            var dim1Filter = new List <string>()
            {
                "JPN", "USD", "__SUM__"
            };
            var dim2Filter = new List <string>()
            {
                "JP", "US"
            };

            MetricsAdvisorClient client = GetMetricsAdvisorClient();

            var options = new GetMetricSeriesDefinitionsOptions(SamplingStartTime);

            options.DimensionCombinationsFilter.Add("Dim1", dim1Filter);
            options.DimensionCombinationsFilter.Add("Dim2", dim2Filter);

            var definitionCount = 0;

            await foreach (MetricSeriesDefinition definition in client.GetMetricSeriesDefinitionsAsync(MetricId, options))
            {
                Assert.That(definition, Is.Not.Null);
                Assert.That(definition.MetricId, Is.EqualTo(MetricId));

                ValidateSeriesKey(definition.SeriesKey);

                DimensionKey seriesKey = definition.SeriesKey;

                Assert.That(seriesKey.TryGetValue("Dim1", out string region));
                Assert.That(seriesKey.TryGetValue("Dim2", out string category));

                Assert.That(dim1Filter.Contains(region));
                Assert.That(dim2Filter.Contains(category));

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

            Assert.That(definitionCount, Is.GreaterThan(0));
        }
コード例 #4
0
        public async Task GetMetricSeriesDefinitionsWithMinimumSetup(bool useTokenCredential)
        {
            MetricsAdvisorClient client = GetMetricsAdvisorClient(useTokenCredential);

            var options = new GetMetricSeriesDefinitionsOptions(SamplingStartTime);

            var definitionCount = 0;

            await foreach (MetricSeriesDefinition definition in client.GetMetricSeriesDefinitionsAsync(MetricId, options))
            {
                Assert.That(definition, Is.Not.Null);
                Assert.That(definition.MetricId, Is.EqualTo(MetricId));

                ValidateSeriesKey(definition.SeriesKey);

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

            Assert.That(definitionCount, Is.GreaterThan(0));
        }
        public async Task GetMetricSeriesDefinitionsAsync()
        {
            string endpoint        = MetricsAdvisorUri;
            string subscriptionKey = MetricsAdvisorSubscriptionKey;
            string apiKey          = MetricsAdvisorApiKey;
            var    credential      = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);

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

            string metricId = MetricId;

            var activeSince = DateTimeOffset.Parse("2020-01-01T00:00:00Z");
            var options     = new GetMetricSeriesDefinitionsOptions(activeSince)
            {
                MaxPageSize = 5
            };

            int definitionCount = 0;

            await foreach (MetricSeriesDefinition definition in client.GetMetricSeriesDefinitionsAsync(metricId, options))
            {
                Console.WriteLine("Time series key:");

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

                Console.WriteLine();

                // Print at most 5 time series.
                if (++definitionCount >= 5)
                {
                    break;
                }
            }
        }