A client used to manage all aspects of a windows azure website
Inheritance: IWebsiteClient
Ejemplo n.º 1
0
        public void Execute()
        {
            //System.Console.WriteLine("reading website");
            //System.Console.WriteLine("================");

            //var client = new WebsiteClient(_subscriptionId, _certificate);
            //var list = client.List();

            //list.ForEach(a => System.Console.WriteLine("Website hosts: " + String.Join(", ", a.Hostname.ToArray())));

            //var client3 = new WebsiteClient(_subscriptionId, _certificate, "ukwaug");
            //System.Console.WriteLine(client3.WebsiteProperties.Config.DetailedErrorLoggingEnabled);
            //var metrics = client3.GetWebsiteMetricsPerInterval(TimeSpan.FromMinutes(600));
            //metrics.ForEach(a => System.Console.WriteLine("Name: {0}, Value: {1} {2}", a.Name, a.Total, a.Units));

            //var engine = new WasabiWebRulesEngine("ukwaug", 5);
            //engine.AddRule(new WasabiWebRule(MetricsConstants.BytesReceived, 10000000, 10000000));
            //engine.AddRule(new WasabiWebRule(MetricsConstants.CpuTime, 560000, 5600000));
            //var connector = new WebsiteManagementConnector(engine, _subscriptionId, WasabiWebLogicalOperation.Or)
            //    {
            //        ManagementCertificate = _certificate
            //    };
            //connector.ScaleUpdate += (state, count) => System.Console.WriteLine("State: {0}, Scale: {1}", state, count);
            //connector.MonitorAndScale();

            var client3 = new WebsiteClient(_subscriptionId, _certificate, "fluentwebtest38");
            client3.Stop();
            client3.Restart();

            var engineAlert = new WasabiWebRulesEngine("fluentwebtest38", 200);
            engineAlert.AddRule(new WasabiWebRule(MetricsConstants.Http2xx, 3));
            var connector2 = new WebsiteManagementConnector(engineAlert, _subscriptionId, WasabiWebLogicalOperation.Or)
            {
                ManagementCertificate = _certificate
            };
            //connector2.SubscribeAlerts +=
            //    (metric, rule) =>
            //    System.Console.WriteLine("Name: {0}, value: {1} {2}", metric.Name, metric.Total, metric.Units);
            //connector2.MonitorAndAlert();
            //connector2.SubscribeAlerts +=
            //    (metric, rule) =>
            //    System.Console.WriteLine("Name: {0}, value: {1} {2}", metric.Name, metric.Total, metric.Units);
            //connector2.MonitorAndAlert();
            connector2.ScaleUpdate += (state, count) => System.Console.WriteLine("State: {0}, Scale: {1}", state, count);
            connector2.MonitorAndScale();
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            var site = new Website()
                           {
                               ComputeMode = ComputeMode.Dedicated,
                               Name = "fluentwebtest38",
                               WebsiteParameters = new WebsiteParameters()
                                                       {
                                                           CurrentNumberOfWorkers = 1
                                                       }
                           };
            site.Config.AppSettings.Add("test1", "test2");
            site.Config.HttpLoggingEnabled = true;
            site.Config.RequestTracingEnabled = true;
            site.Config.DetailedErrorLoggingEnabled = true;
            site.Config.ConnectionStrings.Add(new ConnStringInfo(){Name="test", ConnectionString = "test", Type="SQLAzure"});
            System.Console.WriteLine("Creating website");
            System.Console.WriteLine("================");

            var client = new WebsiteClient(_subscriptionId, _certificate);
            client.CreateFromGithub(site, new GitDetails() { Username = "******", Password = "******", RepositoryName = "test-sample-for-azure-deployments" });
        }
        /// <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;
        }
        /// <summary>
        /// Raises the alert event if any of the metrics have been breached in the time period
        /// </summary>
        public void MonitorAndAlert()
        {
            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));
            // enumerate the metrics piece by piece
            foreach (var metric in metrics)
            {
                // check for the metric to ensure it's in the collection otherwise discard it
                if (_engine[metric.Name] == null)
                    continue;
                var rule = _engine[metric.Name];
                if ((metric.Total > rule.IsGreaterThan || metric.Total < rule.IsLessThan) && SubscribeAlerts != null)
                {
                    SubscribeAlerts(metric, rule);
                }
            }
        }