Beispiel #1
0
        /// <summary>
        /// Shows the mode where the user is only viewing an existing streak type
        /// </summary>
        private void ShowViewMode()
        {
            if (!IsViewMode())
            {
                return;
            }

            var canEdit = CanEdit();

            btnEdit.Visible = canEdit;

            pnlEditDetails.Visible = false;
            pnlViewDetails.Visible = true;
            HideSecondaryBlocks(false);

            // Description
            var node            = WebFarmNode;
            var descriptionList = new DescriptionList();

            descriptionList.Add("Last Seen", node.LastSeen);
            descriptionList.Add("Is Leader", node.IsLeader.ToYesNo());
            descriptionList.Add("Job Runner", node.IsJobRunner.ToYesNo());
            descriptionList.Add("Polling Interval", string.Format("{0:N1}s", node.PollingIntervalSeconds));

            lDescription.Text = descriptionList.Html;

            // Show chart for responsive nodes
            if (node.IsActive && !node.IsUnresponsive && node.Metrics.Count() > 1)
            {
                var samples = WebFarmNodeMetricService.CalculateMetricSamples(node.Metrics, _cpuMetricSampleCount, ChartMinDate, _chartMaxDate);
                var html    = GetChartHtml(samples);
                lChart.Text = html;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds the metrics.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        private static void AddMetrics(RockContext rockContext)
        {
            var webFarmNodeMetricService = new WebFarmNodeMetricService(rockContext);

            if (_cpuCounter != null)
            {
                var cpuPercent = Convert.ToDecimal(_cpuCounter.NextValue());

                webFarmNodeMetricService.Add(
                    new WebFarmNodeMetric
                {
                    WebFarmNodeId = _nodeId,
                    MetricType    = WebFarmNodeMetric.TypeOfMetric.CpuUsagePercent,
                    MetricValue   = cpuPercent
                }
                    );

                Debug($"Added metric: CPU {cpuPercent:N0}%");
            }

            if (_ramCounter != null)
            {
                var ramAvailable = Convert.ToDecimal(_ramCounter.NextValue());
                var ramUsage     = TotalRamMb - ramAvailable;

                webFarmNodeMetricService.Add(
                    new WebFarmNodeMetric
                {
                    WebFarmNodeId = _nodeId,
                    MetricType    = WebFarmNodeMetric.TypeOfMetric.MemoryUsageMegabytes,
                    MetricValue   = ramUsage
                }
                    );

                Debug($"Added metric: RAM {ramUsage:N0}MB");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Handles the ItemDataBound event of the rNodes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param>
        protected void rNodes_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            var viewModel = e.Item.DataItem as WebFarmNodeService.NodeViewModel;

            if (viewModel == null)
            {
                return;
            }

            var spanLastSeen = e.Item.FindControl("spanLastSeen");
            var lChart       = e.Item.FindControl("lChart") as Literal;
            var lLastSeen    = e.Item.FindControl("lLastSeen") as Literal;

            spanLastSeen.Visible = viewModel.IsUnresponsive;
            lLastSeen.Text       = WebFarmNodeService.GetHumanReadablePastTimeDifference(viewModel.LastSeen);

            // Show chart for responsive nodes
            if (viewModel.IsActive && !viewModel.IsUnresponsive && viewModel.Metrics.Count() > 1)
            {
                var samples = WebFarmNodeMetricService.CalculateMetricSamples(viewModel.Metrics, _cpuMetricSampleCount, ChartMinDate, _chartMaxDate);
                var html    = GetChartHtml(samples);
                lChart.Text = html;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Shows the mode where the user is only viewing an existing streak type
        /// </summary>
        private void ShowViewMode()
        {
            if (!IsViewMode())
            {
                return;
            }

            var canEdit = CanEdit();

            btnEdit.Visible = canEdit;

            pnlEditDetails.Visible = false;
            pnlViewDetails.Visible = true;
            HideSecondaryBlocks(false);

            // Load values from system settings
            var minPolling    = RockWebFarm.GetLowerPollingLimitSeconds();
            var maxPolling    = RockWebFarm.GetUpperPollingLimitSeconds();
            var minDifference = RockWebFarm.GetMinimumPollingDifferenceSeconds();
            var pollingWait   = RockWebFarm.GetMaxPollingWaitSeconds();

            var maskedKey = SystemSettings.GetValue(SystemSetting.WEBFARM_KEY).Masked();

            if (maskedKey.IsNullOrWhiteSpace())
            {
                maskedKey = "None";
            }

            // Build the description list with the values
            var descriptionList = new DescriptionList();

            descriptionList.Add("Key", string.Format("{0}", maskedKey));
            descriptionList.Add("Min Polling Limit", string.Format("{0} seconds", minPolling));
            descriptionList.Add("Max Polling Limit", string.Format("{0} seconds", maxPolling));
            descriptionList.Add("Min Polling Difference", string.Format("{0} seconds", minDifference));
            descriptionList.Add("Max Polling Wait", string.Format("{0} seconds", pollingWait));

            var unresponsiveMinutes  = 10;
            var unresponsiveDateTime = RockDateTime.Now.AddMinutes(0 - unresponsiveMinutes);

            // Bind the grid data view models
            using (var rockContext = new RockContext())
            {
                var webFarmNodeService       = new WebFarmNodeService(rockContext);
                var webFarmNodeMetricService = new WebFarmNodeMetricService(rockContext);

                var viewModels = webFarmNodeService.Queryable()
                                 .AsNoTracking()
                                 .Select(wfn => new WebFarmNodeService.NodeViewModel
                {
                    PollingIntervalSeconds = wfn.CurrentLeadershipPollingIntervalSeconds,
                    IsJobRunner            = wfn.IsCurrentJobRunner,
                    IsActive       = wfn.IsActive,
                    IsUnresponsive = wfn.IsActive && !wfn.StoppedDateTime.HasValue && wfn.LastSeenDateTime < unresponsiveDateTime,
                    IsLeader       = wfn.IsLeader,
                    NodeName       = wfn.NodeName,
                    LastSeen       = wfn.LastSeenDateTime,
                    Id             = wfn.Id,
                    Metrics        = wfn.WebFarmNodeMetrics
                                     .Where(wfnm =>
                                            wfnm.MetricType == WebFarmNodeMetric.TypeOfMetric.CpuUsagePercent &&
                                            wfnm.MetricValueDateTime >= ChartMinDate &&
                                            wfnm.MetricValueDateTime <= _chartMaxDate)
                                     .Select(wfnm => new WebFarmNodeMetricService.MetricViewModel
                    {
                        MetricValueDateTime = wfnm.MetricValueDateTime,
                        MetricValue         = wfnm.MetricValue
                    })
                                     .ToList()
                })
                                 .ToList();

                rNodes.DataSource = viewModels.OrderBy(n => n.NodeName);
                rNodes.DataBind();
            }

            lDescription.Text = descriptionList.Html;
        }