public PfcMonitor GetPfcMonitor() { PfcMonitor pfcMonitor = new PfcMonitor { Category = perfCounterPCTypeDdl.SelectedItem.ToString(), Counter = perfCounterCounterNameDdl.SelectedItem. ToString(), Instance = perfCounterInstanceNameDdl.SelectedItem. ToString(), ThresholdWarning = perfCounterTestDataThresholdWarningTextBox.Text, ThresholdPanic = perfCounterTestDataThresholdPanicTextBox.Text, ThresholdBreachCount = Convert.ToInt32( perfCounterTestDataThresholdBreachTextBox. Text), ThresholdLessThan = perfCounterTestDataThresholdLessThanCheckBox. Checked, UpdateFrequency = Convert.ToInt32( perfCounterTestDataUpdateFreqTextBox.Text), Server = IpOrHostName, FriendlyName = FriendlyName }; return pfcMonitor; }
public IMonitor GetCommonMonitor() { switch(_commonType) { case CommonMonitorType.CpuUsage: PfcMonitor cpuUsage = new PfcMonitor { FriendlyName = addServerValidIpMonitorName2.Text, Category = _commonPfcCounter.CategoryName, Counter = _commonPfcCounter.CounterName, Instance = _commonPfcCounter.InstanceName, ThresholdWarning = commonCpuWarningTextBox.Text, ThresholdPanic = commonCpuCriticalTextBox.Text, ThresholdBreachCount = 1, ThresholdLessThan = commonCpuGtLtLabel.Text == "<" ? true : false, Server = addServerValidIpIpTextBox2.Text, UpdateFrequency = Convert.ToInt32(commonMonitorTestDataUpdateFreqTextBox.Text), Common = true }; return cpuUsage; case CommonMonitorType.HddUsage: PfcMonitor hddUsage = new PfcMonitor { FriendlyName = addServerValidIpMonitorName2.Text, Category = _commonPfcCounter.CategoryName, Counter = _commonPfcCounter.CounterName, Instance = _commonPfcCounter.InstanceName, ThresholdWarning = commonHddWarningTextBox.Text, ThresholdPanic = commonHddCriticalTextBox.Text, ThresholdBreachCount = 1, ThresholdLessThan = commonHddGtLtLabel.Text == "<" ? true : false, Server = addServerValidIpIpTextBox2.Text, UpdateFrequency = Convert.ToInt32(commonMonitorTestDataUpdateFreqTextBox.Text), Common = true }; return hddUsage; case CommonMonitorType.MemoryUsage: WmiMonitor memoryUsage = new WmiMonitor { FriendlyName = addServerValidIpMonitorName2.Text, ThresholdWarning = commonMemoryWarningTextBox.Text, ThresholdPanic = commonMemoryCriticalTextBox.Text, ThresholdBreachCount = 1, ThresholdLessThan = commonMemoryGtLtLabel.Text == "<" ? true : false, Server = addServerValidIpIpTextBox2.Text, UpdateFrequency = Convert.ToInt32(commonMonitorTestDataUpdateFreqTextBox.Text), WmiType = commonMemoryUsageTypeDdl.Text == "% In Use" ? WmiType.MemoryUsage : WmiType.MemoryFree, Common = true }; return memoryUsage; case CommonMonitorType.ProcessState: PfcMonitor processState = new PfcMonitor { FriendlyName = addServerValidIpMonitorName2.Text, Category = _commonPfcCounter.CategoryName, Counter = _commonPfcCounter.CounterName, Instance = _commonPfcCounter.InstanceName, ThresholdWarning = commonProcessStateWarningTextBox.Text, ThresholdPanic = commonProcessStateCriticalTextBox.Text, ThresholdBreachCount = 1, ThresholdLessThan = commonProcessStateGtLtLabel.Text == "<" ? true : false, Server = addServerValidIpIpTextBox2.Text, UpdateFrequency = Convert.ToInt32(commonMonitorTestDataUpdateFreqTextBox.Text), Common = true }; return processState; case CommonMonitorType.ServiceState: ServiceMonitor serviceState = new ServiceMonitor { FriendlyName = addServerValidIpMonitorName2.Text, Server = addServerValidIpIpTextBox2.Text, UpdateFrequency = Convert.ToInt32( commonMonitorTestDataUpdateFreqTextBox.Text), AutomaticRestart = false, Common = true }; serviceState.Services.Add(new Service(_commonServiceState.ServiceName)); return serviceState; case CommonMonitorType.SwapFileUsage: PfcMonitor swapFileUsage = new PfcMonitor { FriendlyName = addServerValidIpMonitorName2.Text, Category = _commonPfcCounter.CategoryName, Counter = _commonPfcCounter.CounterName, Instance = _commonPfcCounter.InstanceName, ThresholdWarning = commonSwapFileWarningTextBox.Text, ThresholdPanic = commonSwapFileCriticalTextBox.Text, ThresholdBreachCount = 1, ThresholdLessThan = commonSwapFileGtLtLabel.Text == "<" ? true : false, Server = addServerValidIpIpTextBox2.Text, UpdateFrequency = Convert.ToInt32(commonMonitorTestDataUpdateFreqTextBox.Text), Common = true }; return swapFileUsage; } return null; }
public void PerfCounterRepopulate(PfcMonitor pfc) { alreadyPopulated = true; perfCounterCategories = pfc.Server == "" ? PerformanceCounterCategory.GetCategories() : PerformanceCounterCategory.GetCategories(pfc.Server); for (int x = 0; x < perfCounterCategories.Length; x++) { perfCounterPCTypeDdl.Items.Add(perfCounterCategories[x].CategoryName); } PerformanceCounterCategory pcc = new PerformanceCounterCategory(pfc.Category, pfc.Server); InstanceDataCollectionCollection idcc = pcc.ReadCategory(); perfCounterNames = new List<String>(idcc.Count); foreach (DictionaryEntry idc in idcc) { perfCounterNames.Add(((InstanceDataCollection)idc.Value).CounterName); } perfCounterInstances = new List<String>(pcc.GetInstanceNames()); if (perfCounterNames.Count > 0) perfCounterCounterNameDdl.Items.AddRange(perfCounterNames.ToArray()); else { perfCounterCounterNameDdl.Items.Add("None"); perfCounterCounterNameDdl.SelectedItem = "None"; } if (perfCounterInstances.Count > 0) perfCounterInstanceNameDdl.Items.AddRange(perfCounterInstances.ToArray()); else { perfCounterInstanceNameDdl.Items.Add("None"); perfCounterInstanceNameDdl.SelectedItem = "None"; } try { perfCounterPCTypeDdl.SelectedIndexChanged -= PerfCounterPcTypeDdlSelectedIndexChanged; perfCounterPCTypeDdl.SelectedItem = pfc.Category; perfCounterPCTypeDdl.SelectedIndexChanged += PerfCounterPcTypeDdlSelectedIndexChanged; perfCounterCounterNameDdl.SelectedItem = pfc.Counter; perfCounterInstanceNameDdl.SelectedItem = pfc.Instance; perfCounterTestDataThresholdBreachTextBox.Text = pfc.ThresholdBreachCount.ToString(); perfCounterTestDataThresholdLessThanCheckBox.Checked = pfc.ThresholdLessThan; perfCounterTestDataThresholdPanicTextBox.Text = pfc.ThresholdPanic; perfCounterTestDataThresholdWarningTextBox.Text = pfc.ThresholdWarning; perfCounterTestDataUpdateFreqTextBox.Text = pfc.UpdateFrequency.ToString(); } catch(Exception ex) { Logger.Instance.LogException(this.GetType(), ex); } perfCounterCategoryWaitLabel.Visible = false; perfCounterPCTypeDdl.Visible = true; perfCounterCounterNameWaitLabel.Visible = false; perfCounterCounterNameDdl.Visible = true; perfCounterInstanceNameWaitLabel.Visible = false; perfCounterInstanceNameDdl.Visible = true; }