private void UpdateHealthStats(HealthReportHelper.HealthSetStatistics stats, MonitorAlertState alertValue, DateTime transitionTime) { if (transitionTime > stats.LastTransitionTime) { stats.LastTransitionTime = transitionTime; } stats.TotalCount++; switch (alertValue) { case MonitorAlertState.Healthy: stats.HealthyCount++; return; case MonitorAlertState.Degraded: stats.DegradedCount++; return; case MonitorAlertState.Unhealthy: stats.UnhealthyCount++; return; case MonitorAlertState.Repairing: stats.RepairingCount++; return; case MonitorAlertState.Disabled: stats.DisabledCount++; return; default: stats.UnknownCount++; return; } }
private HealthReportHelper.HealthSetStatistics GetHealthSetStats(IEnumerable <MonitorHealthEntry> entries) { HealthReportHelper.HealthSetStatistics healthSetStatistics = new HealthReportHelper.HealthSetStatistics(); foreach (MonitorHealthEntry monitorHealthEntry in entries) { this.UpdateHealthStats(healthSetStatistics, monitorHealthEntry.AlertValue, monitorHealthEntry.LastTransitionTime); } return(healthSetStatistics); }
internal void ProcessHealth(Action <ConsolidatedHealth> action) { int num = 0; foreach (KeyValuePair <string, Dictionary <string, List <MonitorHealthEntry> > > keyValuePair in this.serverHealthMap) { Dictionary <string, List <MonitorHealthEntry> > value = keyValuePair.Value; if (value != null) { num += value.Count; } } foreach (KeyValuePair <string, Dictionary <string, List <MonitorHealthEntry> > > keyValuePair2 in this.serverHealthMap) { string key = keyValuePair2.Key; Dictionary <string, List <MonitorHealthEntry> > value2 = keyValuePair2.Value; foreach (KeyValuePair <string, List <MonitorHealthEntry> > keyValuePair3 in value2) { string key2 = keyValuePair3.Key; List <MonitorHealthEntry> value3 = keyValuePair3.Value; string healthGroup = null; MonitorServerComponentState state = MonitorServerComponentState.Unknown; if (value3 != null && value3.Count > 0) { MonitorHealthEntry monitorHealthEntry = value3.First <MonitorHealthEntry>(); if (monitorHealthEntry != null) { healthGroup = monitorHealthEntry.HealthGroupName; state = monitorHealthEntry.CurrentHealthSetState; } } int monitorCount = 0; int haImpactingMonitorCount = 0; if (value3 != null) { monitorCount = value3.Count <MonitorHealthEntry>(); haImpactingMonitorCount = value3.Count((MonitorHealthEntry che) => che.IsHaImpacting); } HealthReportHelper.HealthSetStatistics healthSetStats = this.GetHealthSetStats(value3); MonitorAlertState alertValue = this.CalculatedConsolidatedHealthSetAlertValue(healthSetStats); DateTime lastTransitionTime = healthSetStats.LastTransitionTime; ConsolidatedHealth obj = new ConsolidatedHealth(key, key2, healthGroup, alertValue, state, monitorCount, haImpactingMonitorCount, lastTransitionTime, value3); action(obj); } } }
private MonitorAlertState CalculatedConsolidatedHealthSetAlertValue(HealthReportHelper.HealthSetStatistics stats) { MonitorAlertState result = MonitorAlertState.Unknown; if (stats.TotalCount == 0) { result = MonitorAlertState.Healthy; } else if (stats.UnknownCount == stats.TotalCount) { result = MonitorAlertState.Unknown; } else if (stats.DisabledCount == stats.TotalCount) { result = MonitorAlertState.Disabled; } else if (stats.UnhealthyCount > 0) { result = MonitorAlertState.Unhealthy; } else if (stats.DegradedCount > 0) { result = MonitorAlertState.Degraded; } else if (stats.RepairingCount > 0) { result = MonitorAlertState.Repairing; } else if (stats.HealthyCount > 0) { int num = stats.HealthyCount + stats.DisabledCount + stats.UnknownCount; if (num == stats.TotalCount) { result = MonitorAlertState.Healthy; } } return(result); }
internal ConsolidatedHealth ConsolidateAcrossServers(Dictionary <string, ConsolidatedHealth> serverHealthMap) { HealthReportHelper.HealthSetStatistics healthSetStatistics = new HealthReportHelper.HealthSetStatistics(); int num = 0; int num2 = 0; Dictionary <string, ConsolidatedHealth> .ValueCollection values = serverHealthMap.Values; string text = null; string healthGroup = null; List <ConsolidatedHealth> list = new List <ConsolidatedHealth>(); Dictionary <string, ConsolidatedHealth> .ValueCollection values2 = serverHealthMap.Values; int num3 = values2.Count((ConsolidatedHealth health) => health == null); if (num3 > 0) { ConsolidatedHealth consolidatedHealth = serverHealthMap.Values.First((ConsolidatedHealth health) => health != null); if (consolidatedHealth != null) { Dictionary <string, ConsolidatedHealth> dictionary = new Dictionary <string, ConsolidatedHealth>(); foreach (KeyValuePair <string, ConsolidatedHealth> keyValuePair in serverHealthMap) { string key = keyValuePair.Key; if (keyValuePair.Value == null) { ConsolidatedHealth value = new ConsolidatedHealth(key, consolidatedHealth.HealthSet, consolidatedHealth.HealthGroup); dictionary[key] = value; } } foreach (KeyValuePair <string, ConsolidatedHealth> keyValuePair2 in dictionary) { serverHealthMap[keyValuePair2.Key] = keyValuePair2.Value; } } } foreach (ConsolidatedHealth consolidatedHealth2 in values) { if (consolidatedHealth2 != null) { this.UpdateHealthStats(healthSetStatistics, consolidatedHealth2.AlertValue, consolidatedHealth2.LastTransitionTime); if (string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(consolidatedHealth2.HealthSet)) { text = consolidatedHealth2.HealthSet; healthGroup = consolidatedHealth2.HealthGroup; } num += consolidatedHealth2.MonitorCount; num2 += consolidatedHealth2.HaImpactingMonitorCount; list.Add(consolidatedHealth2); } else { this.UpdateHealthStats(healthSetStatistics, MonitorAlertState.Unknown, DateTime.MinValue); } } if (string.IsNullOrEmpty(text)) { text = "Unknown"; healthGroup = "Unknown"; } MonitorAlertState alertValue = this.CalculatedConsolidatedHealthSetAlertValue(healthSetStatistics); DateTime lastTransitionTime = healthSetStatistics.LastTransitionTime; int haImpactingMonitorCount = num2; HealthReportHelper.ServerComponentStateStatistics serverComponentStats = this.GetServerComponentStats(serverHealthMap.Values); MonitorServerComponentState state = this.CalculatedConsolidatedServerComponentState(serverComponentStats); return(new ConsolidatedHealth(text, healthGroup, alertValue, state, num, haImpactingMonitorCount, lastTransitionTime, list)); }