コード例 #1
0
 public AzureMetricsController(
     DashboardRepository dashboardRepository,
     ReportsRepository reportsRepository,
     AzureMetricsClient azureMetricsClient)
 {
     this.dashboardRepository = dashboardRepository;
     this.reportsRepository   = reportsRepository;
     this.azureMetricsClient  = azureMetricsClient;
 }
コード例 #2
0
        private IEnumerable <Instantiation> GenerateRedisAutoscalingRules(SingleStampRuleArguments arguments)
        {
            if (!arguments.DynamicStampProperties.RedisAutoscalingEnabled)
            {
                yield break;
            }

            if (!arguments.EnvironmentResources.RedisCaches.ContainsKey(arguments.StampId.PrimaryRedisName) || !arguments.EnvironmentResources.RedisCaches.ContainsKey(arguments.StampId.SecondaryRedisName))
            {
                _logger.Error($"Attempt to create Redis autoscaler for stamp `{arguments.StampId}` failed due to missing Redis instance. Skipping rule");
                yield break;
            }

            var autoscalingAgentConfiguration = new RedisAutoscalingAgent.Configuration();

            if (arguments.DynamicStampProperties.RedisAutoscalingMaximumClusterMemoryAllowedMb > 0)
            {
                autoscalingAgentConfiguration.MaximumClusterMemoryAllowedMb = arguments.DynamicStampProperties.RedisAutoscalingMaximumClusterMemoryAllowedMb;
            }

            var azureMetricsClient    = new AzureMetricsClient(arguments.EnvironmentResources.MonitorManagementClient);
            var redisAutoscalingAgent = new RedisAutoscalingAgent(autoscalingAgentConfiguration, azureMetricsClient);
            var configuration         = new RedisAutoscalingRule.Configuration(arguments.BaseConfiguration);

            var primaryRedisInstance = RedisInstance
                                       .FromPreloaded(
                arguments.EnvironmentResources.Azure,
                arguments.EnvironmentResources.RedisCaches[arguments.StampId.PrimaryRedisName],
                readOnly: _configuration.ReadOnly)
                                       .ThrowIfFailure();

            var secondaryRedisInstance = RedisInstance
                                         .FromPreloaded(
                arguments.EnvironmentResources.Azure,
                arguments.EnvironmentResources.RedisCaches[arguments.StampId.SecondaryRedisName],
                readOnly: _configuration.ReadOnly)
                                         .ThrowIfFailure();

            yield return(new Instantiation
            {
                Rule = new RedisAutoscalingRule(configuration, redisAutoscalingAgent, primaryRedisInstance, secondaryRedisInstance),
                PollingPeriod = TimeSpan.FromMinutes(10),
            });
        }
コード例 #3
0
        public async Task CanRunMetricsQueryAsync()
        {
            Debugger.Launch();

            LoadApplicationKey().ThrowIfFailure();

            var azure = ExternalDependenciesFactory.CreateAzureClient(Constants.CloudBuildProdAzureCredentials).ThrowIfFailure();

            var redisCaches =
                (azure
                 .RedisCaches
                 .List())
                .ToDictionary(cache => cache.Name, cache => cache);

            var monitorManagementClient = new AzureMetricsClient(await ExternalDependenciesFactory.CreateAzureMetricsClientAsync(Constants.CloudBuildProdAzureCredentials).ThrowIfFailureAsync());

            // var redisCaches = (await azure.RedisCaches.ListAsync()).ToDictionary(cache => cache.Name, cache => cache);

            //"/subscriptions/bf933bbb-8131-491c-81d9-26d7b6f327fa/resourceGroups/CentralUS/providers/Microsoft.Cache/Redis/cbcache-test-redis-dms1"
            //
            var now = DateTime.UtcNow;

            //var metricDfs = (await monitorManagementClient.MetricDefinitions.ListAsync(resourceUri: "/subscriptions/7965fc55-7602-4cf6-abe4-e081cf119567/resourceGroups/EastUS/providers/Microsoft.Cache/Redis/cbcache-prod-redis-bnps01")).ToList();


            //var result = await monitorManagementClient.Metrics.ListAsync(
            //    resourceUri: "/subscriptions/7965fc55-7602-4cf6-abe4-e081cf119567/resourceGroups/EastUS/providers/Microsoft.Cache/Redis/cbcache-prod-redis-bnps01",
            //    odataQuery: new ODataQuery<MetadataValue>($"name.value eq 'UsedMemory'"),
            //    resultType: ResultType.Data);

            //var result = await monitorManagementClient.Metrics.ListAsync(
            //    resourceUri: "/subscriptions/7965fc55-7602-4cf6-abe4-e081cf119567/resourceGroups/CentralUS/providers/Microsoft.Cache/Redis/cbcache-prod-redis-dmps09",
            //    odataQuery: new ODataQuery<MetadataValue>(odataExpression: "ShardId eq '*'"),
            //    timespan: "2020-10-20T21:00:00.000Z/2020-10-27T21:00:00.000Z",
            //    metricnames: "usedmemory",
            //    aggregation: "maximum, minimum",
            //    //metricnamespace: "microsoft.cache/redis",
            //    orderby: "maximum desc",
            //    resultType: ResultType.Data);

            //var metrics = await monitorManagementClient.GetMetricsAsync(
            //    resourceUri: "/subscriptions/7965fc55-7602-4cf6-abe4-e081cf119567/resourceGroups/EastUS/providers/Microsoft.Cache/Redis/cbcache-prod-redis-bnps01",
            //    metrics: new [] {AzureRedisShardMetric.UsedMemory.ToMetricName()},
            //    startTimeUtc: now - TimeSpan.FromDays(7),
            //    endTimeUtc: now,
            //    samplingInterval: TimeSpan.FromMinutes(5),
            //    aggregations: new[] { Microsoft.Azure.Management.Monitor.Models.AggregationType.Maximum, Microsoft.Azure.Management.Monitor.Models.AggregationType.Minimum }
            //    );

            // usedmemory0, usedmemory1, ..., usedmemory9 (today)
            // operationsPerSecond0, ..., 9 (oct 19th)

            /*
             *
             * 0: {httpMethod: "GET",…}
             * httpMethod: "GET"
             * relativeUrl: "/subscriptions/7965fc55-7602-4cf6-abe4-e081cf119567/resourceGroups/CentralUS/providers/Microsoft.Cache/Redis/cbcache-prod-redis-dmps09/providers/microsoft.Insights/metrics?timespan=2020-10-20T21:00:00.000Z/2020-10-27T21:00:00.000Z&interval=FULL&metricnames=usedmemory&aggregation=maximum&metricNamespace=microsoft.cache%2Fredis&top=10&orderby=maximum desc&$filter=ShardId eq '*'&validatedimensions=false&api-version=2019-07-01"
             * 1: {httpMethod: "GET",…}
             *
             */

            // usedmemory per dimension

            var metrics = await monitorManagementClient.GetMetricsWithDimensionAsync(
                resourceUri : "/subscriptions/7965fc55-7602-4cf6-abe4-e081cf119567/resourceGroups/CentralUS/providers/Microsoft.Cache/Redis/cbcache-prod-redis-dmps09",
                metrics : new[] { AzureRedisShardMetric.UsedMemory.ToMetricName() },
                dimension : "ShardId",
                startTimeUtc : now - TimeSpan.FromDays(7),
                endTimeUtc : now,
                samplingInterval : TimeSpan.FromMinutes(5),
                aggregations : new[] { Microsoft.Azure.Management.Monitor.Models.AggregationType.Maximum, Microsoft.Azure.Management.Monitor.Models.AggregationType.Minimum }
                );

            metrics.Count.Should().Be(20);
        }