Exemple #1
0
        /// <summary>
        /// Updates the website based on the scale option
        /// </summary>
        public WasabiWebState MonitorAndScale()
        {
            _timer.Elapsed += (sender, args) => _stateHistory.Add(DateTime.Now, MonitorAndScale());

            EnsureManagementCertificate();

            // use the certificate to run the client and command
            var client = new WebsiteClient(SubscriptionId, ManagementCertificate, _engine.WebsiteName);
            // get the metrics for the timer time period
            var metrics = client.GetWebsiteMetricsPerInterval(TimeSpan.FromMinutes(_engine.SamplesPeriodInMins));

            if (metrics.Count == 0)
            {
                return(WasabiWebState.LeaveUnchanged);
            }

            var scalePotential = _engine.Scale(Operation, metrics);

            // with the scale potential we'll need to increase or decrease the instance count
            if (scalePotential == WasabiWebState.ScaleDown && client.InstanceCount > 1)
            {
                client.InstanceCount -= 1;
            }
            if (scalePotential == WasabiWebState.ScaleUp && client.InstanceCount < 10)
            {
                client.InstanceCount += 1;
            }
            client.Update();
            // raise the event now
            if (ScaleUpdate != null)
            {
                ScaleUpdate(scalePotential, client.InstanceCount);
            }

            return(scalePotential);
        }