Exemplo n.º 1
0
        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.Add(new System.Data.DataColumn("CPU", typeof(string)));
                dt.Columns.Add(new System.Data.DataColumn("Percentage Usage", typeof(double)));
                dt.Columns.Add(new System.Data.DataColumn("User time", typeof(long)));
                dt.Columns.Add(new System.Data.DataColumn("System time", typeof(long)));
                dt.Columns.Add(new System.Data.DataColumn("Idle time", typeof(long)));

                LinuxCPUCollectorConfig currentConfig = (LinuxCPUCollectorConfig)AgentConfig;
                foreach (LinuxCPUEntry entry in currentConfig.Entries)
                {
                    foreach (Linux.CPUInfo cpuInfo in entry.GetCPUInfos())
                    {
                        dt.Rows.Add(entry.SSHConnection.ComputerName, cpuInfo.Name, cpuInfo.CPUPerc, cpuInfo.User, cpuInfo.System, cpuInfo.Idle);
                    }
                }
            }
            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);
        }
Exemplo n.º 2
0
        public override MonitorState RefreshState()
        {
            MonitorState returnState = new MonitorState();
            string       lastAction  = "";
            double       highestVal  = 0;
            int          errors      = 0;
            int          warnings    = 0;
            int          success     = 0;

            try
            {
                LinuxCPUCollectorConfig currentConfig = (LinuxCPUCollectorConfig)AgentConfig;
                foreach (LinuxCPUEntry entry in currentConfig.Entries)
                {
                    MonitorState entryState = new MonitorState()
                    {
                        ForAgent = entry.SSHConnection.ComputerName
                    };

                    foreach (Linux.CPUInfo cpuInfo in  entry.GetCPUInfos())
                    {
                        if (highestVal < cpuInfo.CPUPerc)
                        {
                            highestVal = cpuInfo.CPUPerc;
                        }
                        CollectorState currentState = entry.GetState(cpuInfo.CPUPerc);
                        if (currentState == CollectorState.Error)
                        {
                            errors++;
                        }
                        else if (currentState == CollectorState.Warning)
                        {
                            warnings++;
                        }
                        else
                        {
                            success++;
                        }
                        entryState.ChildStates.Add(
                            new MonitorState()
                        {
                            ForAgent         = cpuInfo.Name,
                            State            = currentState,
                            CurrentValue     = cpuInfo.CPUPerc,
                            CurrentValueUnit = "%"
                        }
                            );
                    }
                    returnState.ChildStates.Add(entryState);
                }
                returnState.CurrentValue     = highestVal;
                returnState.CurrentValueUnit = "% (highest value)";

                if (errors > 0 && warnings == 0 && success == 0) // any errors
                {
                    returnState.State = CollectorState.Error;
                }
                else if (errors > 0 || warnings > 0) //any warnings
                {
                    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);
        }
Exemplo n.º 3
0
 public LinuxCPUCollector()
 {
     AgentConfig = new LinuxCPUCollectorConfig();
 }