//public List<PerfCounterCollectorEntry> Entries = new List<PerfCounterCollectorEntry>(); //public PerfCounterCollectorConfig() //{ // Entries = new List<PerfCounterCollectorEntry>(); //} #region IAgentConfig Members public void ReadConfiguration(string configurationString) { if (configurationString == null || configurationString.Length == 0) { return; } XmlDocument config = new XmlDocument(); config.LoadXml(configurationString); XmlElement root = config.DocumentElement; Entries.Clear(); foreach (XmlElement pcNode in root.SelectNodes("performanceCounters/performanceCounter")) { PerfCounterCollectorEntry entry = new PerfCounterCollectorEntry(); entry.Computer = pcNode.ReadXmlElementAttr("computer", "."); entry.Category = pcNode.ReadXmlElementAttr("category", "Processor"); entry.Counter = pcNode.ReadXmlElementAttr("counter", "% Processor Time"); entry.Instance = pcNode.ReadXmlElementAttr("instance", ""); entry.ReturnValueInverted = bool.Parse(pcNode.ReadXmlElementAttr("returnValueInverted", "False")); entry.WarningValue = float.Parse(pcNode.ReadXmlElementAttr("warningValue", "80")); entry.ErrorValue = float.Parse(pcNode.ReadXmlElementAttr("errorValue", "100")); Entries.Add(entry); } }
private void PerfCounterEditAlert_Shown(object sender, EventArgs e) { currentEntry = new PerfCounterCollectorEntry(); if (SelectedEntry != null) { currentEntry = ((PerfCounterCollectorEntry)SelectedEntry).Clone(); } else //Show add performance window. { PerfCounterEdit editPerfCounter = new PerfCounterEdit(); editPerfCounter.InitialMachine = InitialMachine; editPerfCounter.InitialCategory = "Processor"; editPerfCounter.InitialCounter = "% Processor Time"; editPerfCounter.InitialInstance = "_Total"; if (editPerfCounter.ShowDialog() == System.Windows.Forms.DialogResult.OK) { currentEntry = editPerfCounter.SelectedPCInstance; } else { DialogResult = System.Windows.Forms.DialogResult.Cancel; Close(); return; } } txtPerfCounter.Text = currentEntry.ToString(); warningNumericUpDown.Value = (decimal)currentEntry.WarningValue; errorNumericUpDown.Value = (decimal)currentEntry.ErrorValue; }
public void FromXml(string configurationString) { if (configurationString == null || configurationString.Length == 0) { return; } XmlDocument config = new XmlDocument(); config.LoadXml(configurationString); XmlElement root = config.DocumentElement; Entries.Clear(); foreach (XmlElement pcNode in root.SelectNodes("performanceCounters/performanceCounter")) { PerfCounterCollectorEntry entry = new PerfCounterCollectorEntry(); entry.Computer = pcNode.ReadXmlElementAttr("computer", "."); entry.Category = pcNode.ReadXmlElementAttr("category", "Processor"); entry.Counter = pcNode.ReadXmlElementAttr("counter", "% Processor Time"); entry.Instance = pcNode.ReadXmlElementAttr("instance", ""); entry.WarningValue = float.Parse(pcNode.ReadXmlElementAttr("warningValue", "80")); entry.ErrorValue = float.Parse(pcNode.ReadXmlElementAttr("errorValue", "100")); entry.NumberOfSamplesPerRefresh = pcNode.ReadXmlElementAttr("numberOfSamples", 1); entry.MultiSampleWaitMS = pcNode.ReadXmlElementAttr("multiSampleWaitMS", 100); entry.OutputValueUnit = pcNode.ReadXmlElementAttr("outputValueUnit", ""); entry.PrimaryUIValue = pcNode.ReadXmlElementAttr("primaryUIValue", false); entry.OutputValueScaleFactor = pcNode.ReadXmlElementAttr("valueScale", 1); if (entry.OutputValueScaleFactor == 0) { entry.OutputValueScaleFactor = 1; } entry.OutputValueScaleFactorInverse = pcNode.ReadXmlElementAttr("valueScaleInverse", false); Entries.Add(entry); } }
private void LoadEntryDetails() { optCustom.Checked = true; PerfCounterCollectorEntry currentEntry = (PerfCounterCollectorEntry)SelectedEntry; txtComputerName.Text = currentEntry.Computer; string pcNameWithoutMachineName = currentEntry.PCNameWithoutComputerName; foreach (var commonItem in cboPerformanceCounter.Items) { if (commonItem.ToString().ToLower() == pcNameWithoutMachineName.ToLower()) { cboPerformanceCounter.SelectedItem = commonItem; optCommon.Checked = true; } } txtPerfCounter.Text = currentEntry.Description; warningNumericUpDown.Value = (decimal)currentEntry.WarningValue; errorNumericUpDown.Value = (decimal)currentEntry.ErrorValue; nudNumberOfSamplesPerRefresh.SaveValueSet((decimal)currentEntry.NumberOfSamplesPerRefresh); nudMultiSampleWaitMS.SaveValueSet((decimal)currentEntry.MultiSampleWaitMS); CheckOkEnabled(); }
private void cmdSample_Click(object sender, EventArgs e) { try { PerfCounterCollectorEntry currentEntry = null; if (optCommon.Checked) { currentEntry = PerfCounterCollectorEntry.FromStringDefinition(txtComputerName.Text + "\\" + cboPerformanceCounter.Text); } else { currentEntry = PerfCounterCollectorEntry.FromStringDefinition(txtPerfCounter.Text); } if (currentEntry == null || currentEntry.Computer.Length == 0) { MessageBox.Show("Performance counter definition could not be created!", "Definition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { float val = currentEntry.GetNextValue(); Clipboard.SetText(val.ToString("F4")); MessageBox.Show(string.Format("Current value: {0}", val.ToString("F4")), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static PerfCounterCollectorEntry FromStringDefinition(string definition) { if (definition != null && definition.Length > 0 && definition.Contains('\\') && definition.Split('\\').Length >= 3) { PerfCounterCollectorEntry tmp = new PerfCounterCollectorEntry(); string[] arr = definition.Split('\\'); tmp.Computer = arr[0]; tmp.Category = arr[1]; tmp.Counter = arr[2]; if (arr.Length > 3) { tmp.Instance = ""; for (int i = 3; i < arr.Length; i++) { tmp.Instance += arr[i] + "\\"; } tmp.Instance = tmp.Instance.TrimEnd('\\'); //for when there is no instance (like Category 'Memory') } else { tmp.Instance = ""; } return(tmp); } else { return(null); } }
public PerfCounterCollectorEntry Clone() { PerfCounterCollectorEntry currentEntry = new PerfCounterCollectorEntry(); currentEntry.Computer = Computer; currentEntry.Category = Category; currentEntry.Counter = Counter; currentEntry.Instance = Instance; currentEntry.WarningValue = WarningValue; currentEntry.ErrorValue = ErrorValue; return(currentEntry); }
public QuickMonDialogResult ShowEditEntry() { if (SelectedEntry == null) { SelectedEntry = PerfCounterCollectorEntry.FromStringDefinition(".\\Processor\\% Processor Time\\_Total"); } cboPerformanceCounter.Items.Clear(); cboPerformanceCounter.Items.AddRange(commonEntries.ToArray()); LoadEntryDetails(); return((QuickMonDialogResult)ShowDialog()); }
private void cmdEditPerfCounter_Click(object sender, EventArgs e) { PerfCounterCollectorEntry thisEntry = (PerfCounterCollectorEntry)currentEntry; PerfCounterEdit editPerfCounter = new PerfCounterEdit(); editPerfCounter.InitialMachine = thisEntry.Computer; editPerfCounter.InitialCategory = thisEntry.Category; editPerfCounter.InitialCounter = thisEntry.Counter; editPerfCounter.InitialInstance = thisEntry.Instance; if (editPerfCounter.ShowDialog() == System.Windows.Forms.DialogResult.OK) { currentEntry = editPerfCounter.SelectedPCInstance; txtPerfCounter.Text = currentEntry.ToString(); } }
private void cmdEditPerfCounter_Click(object sender, EventArgs e) { PerfCounterCollectorEntry thisEntry = PerfCounterCollectorEntry.FromStringDefinition(txtPerfCounter.Text); PerfCounterEdit editPerfCounter = new PerfCounterEdit(); editPerfCounter.InitialMachine = thisEntry.Computer; editPerfCounter.InitialCategory = thisEntry.Category; editPerfCounter.InitialCounter = thisEntry.Counter; editPerfCounter.InitialInstance = thisEntry.Instance; if (editPerfCounter.ShowDialog() == System.Windows.Forms.DialogResult.OK) { SelectedEntry = editPerfCounter.SelectedPCInstance; txtPerfCounter.Text = editPerfCounter.SelectedPCInstance.Description; } }
public override void RefreshDisplayData() { Cursor.Current = Cursors.WaitCursor; try { lvwEntries.BeginUpdate(); foreach (ListViewItem lvi in lvwEntries.Items) { try { PerfCounterCollectorEntry pc = (PerfCounterCollectorEntry)lvi.Tag; float currentValue = pc.GetNextValue(); lvi.SubItems[1].Text = currentValue.ToString("F3"); CollectorState currentState = pc.GetState(currentValue); if (currentState == CollectorState.Good) { lvi.ImageIndex = 0; lvi.BackColor = SystemColors.Window; } else if (currentState == CollectorState.Warning) { lvi.ImageIndex = 1; lvi.BackColor = Color.SandyBrown; } else { lvi.ImageIndex = 2; lvi.BackColor = Color.Salmon; } } catch (Exception ex) { lvi.SubItems[1].Text = ex.Message; } } toolStripStatusLabelDetails.Text = "Last updated: " + DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } lvwEntries.EndUpdate(); Cursor.Current = Cursors.Default; }
private void removeToolStripButton_Click(object sender, EventArgs e) { if (SelectedConfig != null) { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig; if (lvwPerfCounters.SelectedItems.Count > 0) { if (MessageBox.Show("Are you sure you want to remove the selected entry(s)?", "Remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { foreach (ListViewItem lvi in lvwPerfCounters.SelectedItems) { PerfCounterCollectorEntry removeItem = (PerfCounterCollectorEntry)lvi.Tag; currentConfig.Entries.Remove(removeItem); lvwPerfCounters.Items.Remove(lvi); } } } } }
private void cmdOK_Click(object sender, EventArgs e) { if (IsValid()) { if (SelectedEntry == null) { SelectedEntry = new PerfCounterCollectorEntry(); } ((PerfCounterCollectorEntry)SelectedEntry).Computer = currentEntry.Computer; ((PerfCounterCollectorEntry)SelectedEntry).Category = currentEntry.Category; ((PerfCounterCollectorEntry)SelectedEntry).Counter = currentEntry.Counter; ((PerfCounterCollectorEntry)SelectedEntry).Instance = currentEntry.Instance; ((PerfCounterCollectorEntry)SelectedEntry).ReturnValueInverted = (warningNumericUpDown.Value > errorNumericUpDown.Value); ((PerfCounterCollectorEntry)SelectedEntry).WarningValue = (float)warningNumericUpDown.Value; ((PerfCounterCollectorEntry)SelectedEntry).ErrorValue = (float)errorNumericUpDown.Value; //SelectedEntry = currentEntry; DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
private void cmdOK_Click(object sender, EventArgs e) { if (CheckForValidCounter()) { SelectedPCInstance = new PerfCounterCollectorEntry() { Computer = txtComputer.Text, Category = lvwCategories.SelectedItems[0].Text, Counter = lvwCounters.SelectedItems[0].Text }; if (lvwInstances.SelectedItems.Count > 0) { SelectedPCInstance.Instance = lvwInstances.SelectedItems[0].Text; } else { SelectedPCInstance.Instance = ""; } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
private void cmdOK_Click(object sender, EventArgs e) { try { if (IsValid()) { PerfCounterCollectorEntry currentEntry = null; if (optCommon.Checked) { currentEntry = PerfCounterCollectorEntry.FromStringDefinition(txtComputerName.Text + "\\" + cboPerformanceCounter.Text); } else { currentEntry = PerfCounterCollectorEntry.FromStringDefinition(txtPerfCounter.Text); } if (currentEntry == null || currentEntry.Computer.Length == 0) { MessageBox.Show("Performance counter definition could not be created!", "Definition", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { currentEntry.WarningValue = (float)warningNumericUpDown.Value; currentEntry.ErrorValue = (float)errorNumericUpDown.Value; currentEntry.NumberOfSamplesPerRefresh = (int)nudNumberOfSamplesPerRefresh.Value; currentEntry.MultiSampleWaitMS = (int)nudMultiSampleWaitMS.Value; SelectedEntry = currentEntry; DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }