示例#1
0
    protected void btnRemove_Click(object sender, EventArgs e)
    {
        string categoryName = string.Empty;
        string counterName = string.Empty;
        string instanceName = string.Empty;

        foreach (GridViewRow row in gridPerfMon.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("chkBoxNotify");

            if (cb != null && cb.Checked)
            {
                Label lblCategory = row.FindControl("lblCategory") as Label;
                categoryName = lblCategory.Text;

                Label lblCounter = row.FindControl("lblCounter") as Label;
                counterName = lblCounter.Text;

                Label lblInstance = row.FindControl("lblInstance") as Label;
                instanceName = lblInstance.Text;

                try
                {
                    BCCPerfCounterEntry entry = new BCCPerfCounterEntry(categoryName, instanceName, counterName);
                    BCCPerfCounterDataAccess da = new BCCPerfCounterDataAccess();
                    da.PerformanceCounterEntryMarkedForDeletion(entry);

                    new ActivityHelper().RaiseAuditEvent(this, lblCaption.Text, "removed '" + counterName + "'", 104);
                    PopulateGrid(sortExpression, lastDirection);
                    AddAnnoucement("You can also disable monitoring of Performance counters instead of removing them.");
                    AddAnnoucement("The BCC agent takes 60 seconds to register changes to the performance counters for monitoring.");
                }
                catch (Exception ex)
                {
                    DisplayError(ex.Message);
                }
            }
        }
    }
        public void CreatePerformanceCounterEntry(BCCPerfCounterEntry entry)
        {
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["authStore"].ConnectionString))
            {
                SqlCommand command = new SqlCommand("[dbo].[bcc_PerfCounterList_CreateEntry]", connection);
                command.CommandType = CommandType.StoredProcedure;

                SqlParameter param = new SqlParameter("@perfCategory", entry.PerfCategory);
                command.Parameters.Add(param);

                param = new SqlParameter("@perfInstance", entry.PerfInstance);
                command.Parameters.Add(param);

                param = new SqlParameter("@perfCounterName", entry.PerfCounter);
                command.Parameters.Add(param);

                param = new SqlParameter("@pollingInterval", 10); // 10 seconds is the new default.
                command.Parameters.Add(param);

                connection.Open();

                command.ExecuteNonQuery();
            }
        }
        public void RemovePerformanceCounterEntry(BCCPerfCounterEntry entry)
        {
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["authStore"].ConnectionString))
            {
                SqlCommand command = new SqlCommand("[dbo].[bcc_PerfCounterList_Delete]", connection);
                command.CommandType = CommandType.StoredProcedure;

                SqlParameter param = new SqlParameter("@perfCategory", entry.PerfCategory);
                command.Parameters.Add(param);

                param = new SqlParameter("@perfInstance", entry.PerfInstance);
                command.Parameters.Add(param);

                param = new SqlParameter("@perfCounterName", entry.PerfCounter);
                command.Parameters.Add(param);

                connection.Open();

                command.ExecuteNonQuery();
            }
        }
        public List<BCCPerfCounterEntry> PerformanceCounterEntryList()
        {
            List<BCCPerfCounterEntry> list = null;

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["authStore"].ConnectionString))
            {
                SqlCommand command = new SqlCommand("[dbo].[bcc_PerfCounterList_List]", connection);
                command.CommandType = CommandType.StoredProcedure;

                connection.Open();

                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);

                list = new List<BCCPerfCounterEntry>();

                BCCPerfCounterEntry entry = null;

                while (reader.Read() )
                {
                    // Create a new list at every instance.
                    entry = new BCCPerfCounterEntry();
                    entry.PerfCategory = (string)reader[0];

                    entry.PerfCounter = (string) reader[1];

                    entry.PerfInstance = (string)reader[2];

                    entry.PollingInterval = (int) reader[3];

                    entry.IsEnabled = (bool)reader[4];

                    entry.IsMarkedForDelete = (bool)reader[5];

                    list.Add(entry);
                }
            }

            return list;
        }
示例#5
0
    protected void gridPerfCounters_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Monitor"))
        {
            LinkButton lnkMonitor = e.CommandSource as LinkButton;

            if (lnkMonitor != null)
            {
                GridViewRow row = (GridViewRow)(lnkMonitor.NamingContainer);

                if (row != null)
                {
                    string categoryName = row.Cells[0].Text;
                    string counterName = row.Cells[3].Text;

                    Label lblInstanceName = row.Cells[2].FindControl("lblInstanceName") as Label;
                    string instanceName = lblInstanceName.Text;

                    string logData = string.Format("setup '{0}::{1}' for monitoring", categoryName, counterName);

                    BCCPerfCounterEntry entry = new BCCPerfCounterEntry(categoryName, instanceName, counterName);

                    if (entry.PerfInstance != string.Empty)
                    {
                        BCCPerfCounterDataAccess dataAccess = new BCCPerfCounterDataAccess();
                        dataAccess.CreatePerformanceCounterEntry(entry);

                        lnkMonitor.Text = "Added";
                        lnkMonitor.Enabled = false;
                    }

                    new ActivityHelper().RaiseAuditEvent(this, lblCaption.Text, logData, 303);
                }

            }
        }
    }
 public BCCPerfCounterMonitor(string category, bool debugFlag, BCCPerfCounterEntry pcounter)
 {
     this.debugFlag = debugFlag;
     this.category = category;
     this.pcounter = pcounter;
 }