Esempio n. 1
0
        public List <Linux.CPUInfo> GetCPUInfos()
        {
            List <Linux.CPUInfo> cpus = new List <Linux.CPUInfo>();

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();
            //using (Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(SSHConnection))
            {
                //if (sshClient.IsConnected)
                {
                    foreach (Linux.CPUInfo ci in Linux.CPUInfo.GetCurrentCPUPerc(sshClient, MSSampleDelay))
                    {
                        if (UseOnlyTotalCPUvalue && ci.IsTotalCPU)
                        {
                            cpus.Add(ci);
                        }
                        else if (!UseOnlyTotalCPUvalue)
                        {
                            cpus.Add(ci);
                        }
                    }
                }
                SSHConnection.CloseConnection();
            }

            return(cpus);
        }
Esempio n. 2
0
        public List <ProcessInfoState> GetStates()
        {
            List <ProcessInfoState> processEntries = new List <ProcessInfoState>();

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();

            LinuxProcessSubEntry globalAlertDef = new LinuxProcessSubEntry();

            globalAlertDef.CPUPercWarningValue = CPUPercWarningValue;
            globalAlertDef.CPUPercErrorValue   = CPUPercErrorValue;
            globalAlertDef.MemPercWarningValue = MemPercWarningValue;
            globalAlertDef.MemPercErrorValue   = MemPercErrorValue;

            List <ProcessInfo> runningProcesses = ProcessInfo.FromPsAux(sshClient);

            if (ProcessCheckOption == ProcessCheckOption.TopXByCPU)
            {
                foreach (ProcessInfo p in (from p in runningProcesses
                                           orderby p.percCPU descending
                                           select p).Take(TopProcessCount))
                {
                    processEntries.Add(new ProcessInfoState()
                    {
                        ProcessInfo = p, AlertDefinition = globalAlertDef
                    });
                }
            }
            else if (ProcessCheckOption == ProcessCheckOption.TopXByMem)
            {
                foreach (ProcessInfo p in (from p in runningProcesses
                                           orderby p.percMEM descending
                                           select p).Take(TopProcessCount))
                {
                    processEntries.Add(new ProcessInfoState()
                    {
                        ProcessInfo = p, AlertDefinition = globalAlertDef
                    });
                }
            }
            else
            {
                foreach (ProcessInfo p in runningProcesses)
                {
                    LinuxProcessSubEntry se = (from LinuxProcessSubEntry sdef in SubItems
                                               where FileNameMatch(p.ProcessName, sdef.ProcessName)
                                               select sdef).FirstOrDefault();
                    if (se != null)
                    {
                        processEntries.Add(new ProcessInfoState()
                        {
                            ProcessInfo = p, AlertDefinition = se
                        });
                    }
                }
            }
            SSHConnection.CloseConnection();
            return(processEntries);
        }
Esempio n. 3
0
        public MemInfo GetMemoryInfo()
        {
            MemInfo mi = new MemInfo();

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();
            mi = MemInfo.FromCatProcMeminfo(sshClient);
            SSHConnection.CloseConnection();
            return(mi);
        }
Esempio n. 4
0
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent         = Description,
                State            = CollectorState.NotAvailable,
                CurrentValueUnit = "%"
            };

            try
            {
                MemInfo mi = new MemInfo();
                Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();
                mi = MemInfo.FromCatProcMeminfo(sshClient);
                SSHConnection.CloseConnection();
                double outputValue = 0;
                if (MemoryType == LinuxMemoryType.MemAvailable)
                {
                    outputValue = mi.AvailablePerc;
                    if (outputValue == 0 && mi.TotalKB > 0)
                    {
                        outputValue = (mi.FreeKB + mi.Buffers + mi.Cached) / mi.TotalKB;
                    }
                }
                else if (MemoryType == LinuxMemoryType.MemFree)
                {
                    outputValue = mi.FreePerc;
                }
                else
                {
                    outputValue = mi.SwapFreePerc;
                }
                currentState.CurrentValue = outputValue.ToString("0.0");
                if (ErrorValue >= outputValue)
                {
                    currentState.State = CollectorState.Error;
                }
                else if (WarningValue >= outputValue)
                {
                    currentState.State = CollectorState.Warning;
                }
                else
                {
                    currentState.State = CollectorState.Good;
                }
            }
            catch (Exception ex)
            {
                currentState.State      = CollectorState.Error;
                currentState.RawDetails = ex.Message;
            }
            return(currentState);
        }
Esempio n. 5
0
        public List <DiskInfoState> GetDiskInfos()
        {
            List <DiskInfoState> fileSystemEntries = new List <DiskInfoState>();

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();


            //First see if ANY subentry is for all
            bool addAll = (from LinuxDiskSpaceSubEntry d in SubItems
                           where d.FileSystemName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                LinuxDiskSpaceSubEntry alertDef = (from LinuxDiskSpaceSubEntry d in SubItems
                                                   where d.FileSystemName == "*"
                                                   select d).FirstOrDefault();
                foreach (Linux.DiskInfo di in DiskInfo.FromDfTk(sshClient))
                {
                    DiskInfoState dis = new DiskInfoState()
                    {
                        FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    fileSystemEntries.Add(dis);
                }
            }
            else
            {
                foreach (Linux.DiskInfo di in DiskInfo.FromDfTk(sshClient))
                {
                    LinuxDiskSpaceSubEntry alertDef = (from LinuxDiskSpaceSubEntry d in SubItems
                                                       where d.FileSystemName.ToLower() == di.Name.ToLower()
                                                       select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!fileSystemEntries.Any(f => f.FileSystemInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            DiskInfoState dis = new DiskInfoState()
                            {
                                FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            fileSystemEntries.Add(dis);
                        }
                    }
                }
            }
            SSHConnection.CloseConnection();
            return(fileSystemEntries);
        }
Esempio n. 6
0
        public List <NICState> GetNICInfos()
        {
            List <NICState> nicEntries = new List <NICState>();

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();

            //First see if ANY subentry is for all
            bool addAll = (from LinuxNICSubEntry d in SubItems
                           where d.NICName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                LinuxNICSubEntry alertDef = (from LinuxNICSubEntry d in SubItems
                                             where d.NICName == "*"
                                             select d).FirstOrDefault();
                foreach (Linux.NicInfo ni in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NICState nis = new NICState()
                    {
                        NICInfo = ni, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    nicEntries.Add(nis);
                }
            }
            else
            {
                foreach (Linux.NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    LinuxNICSubEntry alertDef = (from LinuxNICSubEntry d in SubItems
                                                 where d.NICName.ToLower() == di.Name.ToLower()
                                                 select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!nicEntries.Any(f => f.NICInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            NICState dis = new NICState()
                            {
                                NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            nicEntries.Add(dis);
                        }
                    }
                }
                SSHConnection.CloseConnection();
            }
            return(nicEntries);
        }
Esempio n. 7
0
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent         = Description,
                State            = CollectorState.Good,
                CurrentValueUnit = "%"
            };

            try
            {
                Renci.SshNet.SshClient sshConnection = SSHConnection.GetConnection();
                List <CPUInfo>         cpuInfos      = CPUInfo.GetCurrentCPUPerc(sshConnection, MSSampleDelay);
                SSHConnection.CloseConnection();
                currentState.State = CollectorState.NotAvailable;
                if (cpuInfos.Count > 0)
                {
                    currentState.CurrentValue = cpuInfos[0].CPUPerc.ToString("0.0");
                    currentState.State        = GetState(cpuInfos[0].CPUPerc);
                }

                for (int i = 1; i < cpuInfos.Count; i++)
                {
                    CollectorState currentCPUState = GetState(cpuInfos[i].CPUPerc);
                    if ((int)currentCPUState > (int)currentState.State && !UseOnlyTotalCPUvalue)
                    {
                        currentState.CurrentValue = cpuInfos[i].CPUPerc.ToString("0.0");
                        currentState.State        = currentCPUState;
                    }
                    MonitorState cpuState = new MonitorState()
                    {
                        ForAgent         = cpuInfos[i].Name,
                        State            = currentCPUState,
                        CurrentValue     = cpuInfos[i].CPUPerc.ToString("0.0"),
                        CurrentValueUnit = "%"
                    };
                    currentState.ChildStates.Add(cpuState);
                }
            }
            catch (Exception wsException)
            {
                currentState.State      = CollectorState.Error;
                currentState.RawDetails = wsException.Message;
            }

            return(currentState);
        }
Esempio n. 8
0
        public string ExecuteCommand()
        {
            string output = "";

            try
            {
                Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();
                //using (Renci.SshNet.SshClient sshClient = SshClientTools.GetSSHConnection(SSHConnection))
                {
                    try
                    {
                        //if (sshClient.IsConnected)
                        {
                            output = sshClient.RunCommand(CommandString).Result;
                        }
                        SSHConnection.CloseConnection();

                        if (ValueReturnType == SSHCommandValueReturnType.LineCount)
                        {
                            int lines = output.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length;
                            output = lines.ToString();
                        }
                        else if (ValueReturnType == SSHCommandValueReturnType.TextLength)
                        {
                            int length = output.Length;
                            output = length.ToString();
                        }
                    }
                    catch (Exception ex)
                    {
                        output = string.Format("The Command '{0}' failed to execute!\r\n{1}", CommandString, ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Connection failed to '{0}' : {1}", SSHConnection.ComputerName, ex.Message));
            }

            return(output);
        }
Esempio n. 9
0
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent     = Description,
                State        = CollectorState.None,
                CurrentValue = ""
            };

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();

            #region Get Disk infos and states
            List <DiskSpaceInfoState> fileSystemEntries = new List <DiskSpaceInfoState>();
            //First see if ANY subentry is for all
            bool addAll = (from NIXDiskSpaceSubEntry d in SubItems
                           where d.FileSystemName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                NIXDiskSpaceSubEntry alertDef = (from NIXDiskSpaceSubEntry d in SubItems
                                                 where d.FileSystemName == "*"
                                                 select d).FirstOrDefault();
                alertDef.PrimaryUIValue = false;
                foreach (DiskInfo di in DiskInfo.FromDfTk(sshClient))
                {
                    DiskSpaceInfoState dis = new DiskSpaceInfoState()
                    {
                        FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    fileSystemEntries.Add(dis);
                }
            }
            else
            {
                foreach (DiskInfo di in DiskInfo.FromDfTk(sshClient))
                {
                    NIXDiskSpaceSubEntry alertDef = (from NIXDiskSpaceSubEntry d in SubItems
                                                     where d.FileSystemName.ToLower() == di.Name.ToLower()
                                                     select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!fileSystemEntries.Any(f => f.FileSystemInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            DiskSpaceInfoState dis = new DiskSpaceInfoState()
                            {
                                FileSystemInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            fileSystemEntries.Add(dis);
                        }
                    }
                }
            }
            #endregion

            SSHConnection.CloseConnection();

            int    errors   = 0;
            int    warnings = 0;
            int    success  = 0;
            double average  = 0;
            foreach (DiskSpaceInfoState dis in fileSystemEntries)
            {
                average += dis.FileSystemInfo.FreeSpacePerc;
                if (dis.FileSystemInfo.FreeSpacePerc <= dis.AlertDefinition.ErrorValue)
                {
                    dis.State = CollectorState.Error;
                    errors++;
                }
                else if (dis.FileSystemInfo.FreeSpacePerc <= dis.AlertDefinition.WarningValue)
                {
                    dis.State = CollectorState.Warning;
                    warnings++;
                }
                else
                {
                    dis.State = CollectorState.Good;
                    success++;
                }
                if (dis.AlertDefinition.PrimaryUIValue)
                {
                    currentState.CurrentValue     = dis.FileSystemInfo.FreeSpacePerc.ToString("0.0");
                    currentState.CurrentValueUnit = "%";
                }

                MonitorState fileSystemState = new MonitorState()
                {
                    ForAgent         = dis.FileSystemInfo.Name,
                    State            = dis.State,
                    CurrentValue     = dis.FileSystemInfo.FreeSpacePerc.ToString("0.0"),
                    CurrentValueUnit = "%",
                    PrimaryUIValue   = dis.AlertDefinition.PrimaryUIValue
                };
                currentState.ChildStates.Add(fileSystemState);
            }
            if (errors > 0 && warnings == 0 && success == 0) // any errors
            {
                currentState.State = CollectorState.Error;
            }
            else if (errors > 0 || warnings > 0) //any warnings
            {
                currentState.State = CollectorState.Warning;
            }
            else
            {
                currentState.State = CollectorState.Good;
            }

            if (currentState.CurrentValue.ToString() == "" && currentState.ChildStates.Count > 0)
            {
                currentState.CurrentValue     = (average / currentState.ChildStates.Count).ToString("0.0");
                currentState.CurrentValueUnit = "% (avg)";
            }

            return(currentState);
        }
Esempio n. 10
0
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent     = Description,
                State        = CollectorState.None,
                CurrentValue = ""
            };

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();

            #region Get Disk infos and states
            List <NICInfoState> nicEntries = new List <NICInfoState>();
            //First see if ANY subentry is for all
            bool addAll = (from NIXNICSubEntry d in SubItems
                           where d.NICName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                NIXNICSubEntry alertDef = (from NIXNICSubEntry d in SubItems
                                           where d.NICName == "*"
                                           select d).FirstOrDefault();
                alertDef.PrimaryUIValue = false;
                foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NICInfoState dis = new NICInfoState()
                    {
                        NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    nicEntries.Add(dis);
                }
            }
            else
            {
                foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient, 250))
                {
                    NIXNICSubEntry alertDef = (from NIXNICSubEntry d in SubItems
                                               where d.NICName.ToLower() == di.Name.ToLower()
                                               select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!nicEntries.Any(f => f.NICInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            NICInfoState dis = new NICInfoState()
                            {
                                NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            nicEntries.Add(dis);
                        }
                    }
                }
            }
            #endregion

            SSHConnection.CloseConnection();

            int    errors   = 0;
            int    warnings = 0;
            int    success  = 0;
            double average  = 0;
            foreach (NICInfoState dis in nicEntries)
            {
                average += dis.NICInfo.RTxBytesPerSec;
                if (dis.NICInfo.RTxBytesPerSec >= dis.AlertDefinition.ErrorValueKB * 1024)
                {
                    dis.State = CollectorState.Error;
                }
                else if (dis.NICInfo.RTxBytesPerSec >= dis.AlertDefinition.WarningValueKB * 1024)
                {
                    dis.State = CollectorState.Warning;
                }
                else
                {
                    dis.State = CollectorState.Good;
                    success++;
                }
                if (dis.AlertDefinition.PrimaryUIValue)
                {
                    currentState.CurrentValue     = dis.NICInfo.RTxBytesPerSec.ToString("0");
                    currentState.CurrentValueUnit = "Bytes/Sec";
                }

                MonitorState diskIOState = new MonitorState()
                {
                    ForAgent         = dis.NICInfo.Name,
                    State            = dis.State,
                    CurrentValue     = dis.NICInfo.RTxBytesPerSec.ToString("0"),
                    CurrentValueUnit = "Bytes/Sec",
                    PrimaryUIValue   = dis.AlertDefinition.PrimaryUIValue
                };
                currentState.ChildStates.Add(diskIOState);
            }
            if (errors > 0 && warnings == 0 && success == 0) // any errors
            {
                currentState.State = CollectorState.Error;
            }
            else if (errors > 0 || warnings > 0) //any warnings
            {
                currentState.State = CollectorState.Warning;
            }
            else
            {
                currentState.State = CollectorState.Good;
            }

            if (currentState.CurrentValue.ToString() == "" && currentState.ChildStates.Count > 0)
            {
                currentState.CurrentValue     = (average / currentState.ChildStates.Count).ToString("0.0");
                currentState.CurrentValueUnit = "Bytes/Sec (avg)";
            }

            return(currentState);
        }
Esempio n. 11
0
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent     = Description,
                State        = CollectorState.None,
                CurrentValue = ""
            };

            Renci.SshNet.SshClient sshClient = SSHConnection.GetConnection();

            #region Get Disk infos and states
            List <DiskIOInfoState> diskEntries = new List <DiskIOInfoState>();
            //First see if ANY subentry is for all
            bool addAll = (from NIXDiskIOSubEntry d in SubItems
                           where d.DiskName == "*"
                           select d).Count() > 0;

            if (addAll)
            {
                NIXDiskIOSubEntry alertDef = (from NIXDiskIOSubEntry d in SubItems
                                              where d.DiskName == "*"
                                              select d).FirstOrDefault();
                alertDef.PrimaryUIValue = false;
                foreach (DiskIOInfo di in DiskIOInfo.GetCurrentDiskStats(sshClient, 250))
                {
                    DiskIOInfoState dis = new DiskIOInfoState()
                    {
                        DiskInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    diskEntries.Add(dis);
                }
            }
            else
            {
                foreach (DiskIOInfo di in DiskIOInfo.GetCurrentDiskStats(sshClient, 250))
                {
                    NIXDiskIOSubEntry alertDef = (from NIXDiskIOSubEntry d in SubItems
                                                  where d.DiskName.ToLower() == di.Name.ToLower()
                                                  select d).FirstOrDefault();

                    if (alertDef != null)
                    {
                        if (!diskEntries.Any(f => f.DiskInfo.Name.ToLower() == di.Name.ToLower()))
                        {
                            DiskIOInfoState dis = new DiskIOInfoState()
                            {
                                DiskInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                            };
                            diskEntries.Add(dis);
                        }
                    }
                }
            }
            #endregion

            SSHConnection.CloseConnection();

            int    errors   = 0;
            int    warnings = 0;
            int    success  = 0;
            double average  = 0;
            foreach (DiskIOInfoState dis in diskEntries)
            {
                average += dis.DiskInfo.BytesReadWritePerSec;
                if (dis.DiskInfo.BytesReadWritePerSec >= (dis.AlertDefinition.ErrorValueKB * 1024))
                {
                    dis.State = CollectorState.Error;
                    errors++;
                }
                else if (dis.DiskInfo.BytesReadWritePerSec >= (dis.AlertDefinition.WarningValueKB * 1024))
                {
                    dis.State = CollectorState.Warning;
                    warnings++;
                }
                else
                {
                    dis.State = CollectorState.Good;
                    success++;
                }
                string formatValue = FormatUtils.FormatFileSizePerSec(dis.DiskInfo.BytesReadWritePerSec);
                if (dis.AlertDefinition.PrimaryUIValue)
                {
                    currentState.CurrentValue     = formatValue.Split(' ')[0];
                    currentState.CurrentValueUnit = formatValue.Split(' ')[1];
                }

                MonitorState diskIOState = new MonitorState()
                {
                    ForAgent         = dis.DiskInfo.Name,
                    State            = dis.State,
                    CurrentValue     = formatValue.Split(' ')[0],
                    CurrentValueUnit = formatValue.Split(' ')[1],
                    PrimaryUIValue   = dis.AlertDefinition.PrimaryUIValue
                };
                currentState.ChildStates.Add(diskIOState);
            }
            if (errors > 0 && warnings == 0 && success == 0) // any errors
            {
                currentState.State = CollectorState.Error;
            }
            else if (errors > 0 || warnings > 0) //any warnings
            {
                currentState.State = CollectorState.Warning;
            }
            else
            {
                currentState.State = CollectorState.Good;
            }

            if (currentState.CurrentValue.ToString() == "" && currentState.ChildStates.Count > 0)
            {
                string formatValue = FormatUtils.FormatFileSizePerSec((long)((average / currentState.ChildStates.Count)));
                currentState.CurrentValue     = formatValue.Split(' ')[0];
                currentState.CurrentValueUnit = formatValue.Split(' ')[1];
            }

            return(currentState);
        }