private void addCloneComputerToolStripMenuItem_Click(object sender, EventArgs e) { if (SelectedConfig != null) { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig; if (lvwPerfCounters.SelectedItems.Count > 0) { PerfCounterEditAlert editPerfCounterAlert = new PerfCounterEditAlert(); editPerfCounterAlert.InitialMachine = ((PerfCounterCollectorEntry)lvwPerfCounters.SelectedItems[0].Tag).Computer; if (editPerfCounterAlert.ShowDialog() == System.Windows.Forms.DialogResult.OK) { currentConfig.Entries.Add(editPerfCounterAlert.SelectedPCInstance); ListViewItem lvi = new ListViewItem(editPerfCounterAlert.SelectedPCInstance.ToString()); if (editPerfCounterAlert.SelectedPCInstance.WarningValue < 9999) { lvi.SubItems.Add(string.Format("{0:f3}", editPerfCounterAlert.SelectedPCInstance.WarningValue)); } else { lvi.SubItems.Add(string.Format("{0:f1}", editPerfCounterAlert.SelectedPCInstance.WarningValue)); } if (editPerfCounterAlert.SelectedPCInstance.ErrorValue < 9999) { lvi.SubItems.Add(string.Format("{0:f3}", editPerfCounterAlert.SelectedPCInstance.ErrorValue)); } else { lvi.SubItems.Add(string.Format("{0:f1}", editPerfCounterAlert.SelectedPCInstance.ErrorValue)); } lvi.Tag = editPerfCounterAlert.SelectedPCInstance; lvwPerfCounters.Items.Add(lvi); } } } }
private void cmdOK_Click(object sender, EventArgs e) { if (SelectedConfig != null) { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig; currentConfig.Entries.Clear(); foreach (ListViewItem lvi in lvwPerfCounters.Items) { if (lvi.Tag is PerfCounterCollectorEntry) { currentConfig.Entries.Add((PerfCounterCollectorEntry)lvi.Tag); } } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
private void LoadEntries() { try { lvwPerfCounters.BeginUpdate(); lvwPerfCounters.Items.Clear(); if (SelectedConfig != null) { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig; foreach (PerfCounterCollectorEntry entry in currentConfig.Entries) { ListViewItem lvi = new ListViewItem(entry.ToString()); if (entry.WarningValue < 9999) { lvi.SubItems.Add(string.Format("{0:f3}", entry.WarningValue)); } else { lvi.SubItems.Add(string.Format("{0:f1}", entry.WarningValue)); } if (entry.ErrorValue < 9999) { lvi.SubItems.Add(string.Format("{0:f3}", entry.ErrorValue)); } else { lvi.SubItems.Add(string.Format("{0:f1}", entry.ErrorValue)); } lvi.Tag = entry; lvwPerfCounters.Items.Add(lvi); } } lvwPerfCounters_Resize(lvwPerfCounters, null); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { lvwPerfCounters.EndUpdate(); } }
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 editToolStripButton_Click(object sender, EventArgs e) { if (SelectedConfig != null) { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig; if (lvwPerfCounters.SelectedItems.Count > 0) { PerfCounterEditAlert editPerfCounterAlert = new PerfCounterEditAlert(); editPerfCounterAlert.SelectedPCInstance = (PerfCounterCollectorEntry)lvwPerfCounters.SelectedItems[0].Tag; if (editPerfCounterAlert.ShowDialog() == System.Windows.Forms.DialogResult.OK) { lvwPerfCounters.SelectedItems[0].Tag = editPerfCounterAlert.SelectedPCInstance; lvwPerfCounters.SelectedItems[0].Text = editPerfCounterAlert.SelectedPCInstance.ToString(); lvwPerfCounters.SelectedItems[0].SubItems[1].Text = string.Format("{0:f2}", editPerfCounterAlert.SelectedPCInstance.WarningValue); lvwPerfCounters.SelectedItems[0].SubItems[2].Text = string.Format("{0:f2}", editPerfCounterAlert.SelectedPCInstance.ErrorValue); } } } }
private void cmdQuickConfig_Click(object sender, EventArgs e) { switch (cboQuickConfig.SelectedIndex) { case 0: if (SelectedConfig != null) { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig; if (currentConfig.Entries != null && currentConfig.Entries.Count > 0 && MessageBox.Show("Do you want to replace any existing config?", "Config", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) { break; } } SelectedConfig = new PerfCounterCollectorConfig(); SelectedConfig.ReadConfiguration(Properties.Resources.PerfCounterCollectorQuickConfig1); LoadEntries(); break; case 1: if (SelectedConfig != null) { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)SelectedConfig; if (currentConfig.Entries != null && currentConfig.Entries.Count > 0 && MessageBox.Show("Do you want to replace any existing config?", "Config", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) { break; } } SelectedConfig = new PerfCounterCollectorConfig(); string customConfigString = Properties.Resources.PerfCounterCollectorQuickConfig2; string machineName = QuickMon.Forms.InputBox.Show("Specify computer name", "Computer", ""); if (machineName.Length > 0) { customConfigString = customConfigString.Replace("[machineName]", machineName); SelectedConfig.ReadConfiguration(customConfigString); LoadEntries(); } break; default: break; } }
public override List <System.Data.DataTable> GetDetailDataTables() { List <System.Data.DataTable> tables = new List <System.Data.DataTable>(); System.Data.DataTable dt = new System.Data.DataTable(); try { dt.Columns.Add(new System.Data.DataColumn("Computer", typeof(string))); dt.Columns[0].ExtendedProperties.Add("groupby", "true"); dt.Columns.Add(new System.Data.DataColumn("Perf counter", typeof(string))); dt.Columns.Add(new System.Data.DataColumn("Value", typeof(float))); PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)AgentConfig; foreach (PerfCounterCollectorEntry entry in currentConfig.Entries) { float value = 0; try { value = entry.GetNextValue(); } catch { value = -1; } dt.Rows.Add(entry.Computer, entry.PCNameWithoutComputerName, value); } } catch (Exception ex) { dt = new System.Data.DataTable("Exception"); dt.Columns.Add(new System.Data.DataColumn("Text", typeof(string))); dt.Rows.Add(ex.ToString()); } tables.Add(dt); return(tables); }
public PerfCounterCollector() { AgentConfig = new PerfCounterCollectorConfig(); }
public override MonitorState RefreshState() { MonitorState returnState = new MonitorState(); string lastAction = ""; int errors = 0; int warnings = 0; int success = 0; string outputFormat = "F3"; try { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)AgentConfig; returnState.RawDetails = string.Format("Querying {0} performance counters", currentConfig.Entries.Count); returnState.HtmlDetails = string.Format("<i>Querying {0} performance counters</i>", currentConfig.Entries.Count); foreach (PerfCounterCollectorEntry entry in currentConfig.Entries) { CollectorState currentState = CollectorState.Good; float value = 0; outputFormat = "F3"; try { value = entry.GetNextValue(); if (value > 9999) { outputFormat = "F1"; } currentState = entry.GetState(value); if (currentState == CollectorState.Error) { errors++; returnState.ChildStates.Add( new MonitorState() { State = CollectorState.Error, ForAgent = entry.Description, CurrentValue = value.ToString(outputFormat), RawDetails = string.Format("(Trigger {0})", entry.ErrorValue.ToString(outputFormat)) //RawDetails = string.Format("{0} - Val: '{1}' - Error (trigger '{2}')", entry.Description, value.ToString(outputFormat), entry.ErrorValue.ToString(outputFormat)), //HtmlDetails = string.Format("{0} - Val: '{1}' - <b>Error</b> (trigger '{2}')", entry.Description, value.ToString(outputFormat), entry.ErrorValue.ToString(outputFormat)) }); } else if (currentState == CollectorState.Warning) { warnings++; returnState.ChildStates.Add( new MonitorState() { State = CollectorState.Warning, ForAgent = entry.Description, CurrentValue = value, RawDetails = string.Format("(Trigger {0})", entry.WarningValue.ToString(outputFormat)) //RawDetails = string.Format("{0} - Val: '{1}' - Warning (trigger '{2}')", entry.Description, value.ToString(outputFormat), entry.WarningValue.ToString(outputFormat)), //HtmlDetails = string.Format("{0} - Val: '{1}' - <b>Warning</b> (trigger '{2}')", entry.Description, value.ToString(outputFormat), entry.WarningValue.ToString(outputFormat)) }); } else { success++; returnState.ChildStates.Add( new MonitorState() { State = CollectorState.Good, ForAgent = entry.Description, CurrentValue = value //, //RawDetails = string.Format("{0} - Val: '{1}'", entry.Description, value.ToString(outputFormat)), //HtmlDetails = string.Format("{0} - Val: '{1}'", entry.Description, value.ToString(outputFormat)) }); } } catch (Exception ex) { errors++; returnState.ChildStates.Add(new MonitorState() { State = CollectorState.Error, ForAgent = entry.Description, RawDetails = ex.Message }); } } if (errors > 0 && warnings == 0 && success == 0) { returnState.State = CollectorState.Error; } else if (errors > 0 || warnings > 0) { returnState.State = CollectorState.Warning; } else { returnState.State = CollectorState.Good; } } catch (Exception ex) { returnState.RawDetails = ex.Message; returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message); returnState.State = CollectorState.Error; } return(returnState); }
public override MonitorState GetState() { MonitorState returnState = new MonitorState(); StringBuilder plainTextDetails = new StringBuilder(); StringBuilder htmlTextTextDetails = new StringBuilder(); string lastAction = ""; int errors = 0; int warnings = 0; int success = 0; string outputFormat = "F3"; string lastErrMsg = ""; try { PerfCounterCollectorConfig currentConfig = (PerfCounterCollectorConfig)AgentConfig; plainTextDetails.AppendLine(string.Format("Querying {0} performance counters", currentConfig.Entries.Count)); htmlTextTextDetails.AppendLine(string.Format("<i>Querying {0} performance counters</i>", currentConfig.Entries.Count)); htmlTextTextDetails.AppendLine("<ul>"); foreach (PerfCounterCollectorEntry entry in currentConfig.Entries) { CollectorState currentState = CollectorState.Good; float value = 0; outputFormat = "F3"; try { value = entry.GetNextValue(); if (value > 9999) { outputFormat = "F1"; } currentState = entry.GetState(value); lastErrMsg = ""; } catch (Exception ex) { lastErrMsg = ex.Message; currentState = CollectorState.Error; } if (currentState == CollectorState.Error) { errors++; plainTextDetails.AppendLine(string.Format("\t{0} - value '{1}' - Error (trigger '{2}') {3}", entry.ToString(), value.ToString(outputFormat), entry.ErrorValue.ToString(outputFormat), lastErrMsg)); htmlTextTextDetails.AppendLine(string.Format("<li>{0} - value '{1}' - <b>Error</b> (trigger '{2}') {3} </li>", entry.ToString(), value.ToString(outputFormat), entry.ErrorValue.ToString(outputFormat), lastErrMsg)); } else if (currentState == CollectorState.Warning) { warnings++; plainTextDetails.AppendLine(string.Format("\t{0} - value '{1}' - Warning (trigger '{2}')", entry.ToString(), value.ToString(outputFormat), entry.WarningValue.ToString(outputFormat))); htmlTextTextDetails.AppendLine(string.Format("<li>{0} - value '{1}' - <b>Warning</b> (trigger '{2}')</li>", entry.ToString(), value.ToString(outputFormat), entry.WarningValue.ToString(outputFormat))); } else { success++; plainTextDetails.AppendLine(string.Format("\t{0} - value '{1}'", entry.ToString(), value.ToString(outputFormat))); htmlTextTextDetails.AppendLine(string.Format("<li>{0} - value '{1}'</li>", entry.ToString(), value.ToString(outputFormat))); } } htmlTextTextDetails.AppendLine("</ul>"); returnState.RawDetails = plainTextDetails.ToString().TrimEnd('\r', '\n'); returnState.HtmlDetails = htmlTextTextDetails.ToString(); if (errors > 0 && warnings == 0 && success == 0) { returnState.State = CollectorState.Error; } else if (errors > 0 || warnings > 0) { returnState.State = CollectorState.Warning; } else { returnState.State = CollectorState.Good; } } catch (Exception ex) { returnState.RawDetails = ex.Message; returnState.HtmlDetails = string.Format("<p><b>Last action:</b> {0}</p><blockquote>{1}</blockquote>", lastAction, ex.Message); returnState.State = CollectorState.Error; } return(returnState); }