Exemple #1
0
        public override MonitorState GetCurrentState()
        {
            MonitorState currentState = new MonitorState()
            {
                ForAgent     = Description,
                State        = CollectorState.None,
                CurrentValue = ""
            };

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

            #region Get NIC 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, MeasuringDelayMS))
                {
                    NICInfoState dis = new NICInfoState()
                    {
                        NICInfo = di, State = CollectorState.NotAvailable, AlertDefinition = alertDef
                    };
                    nicEntries.Add(dis);
                }
            }
            else
            {
                foreach (NicInfo di in NicInfo.GetCurrentNicStats(sshClient, MeasuringDelayMS))
                {
                    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;
                    errors++;
                }
                else if (dis.NICInfo.RTxBytesPerSec >= dis.AlertDefinition.WarningValueKB * 1024)
                {
                    dis.State = CollectorState.Warning;
                    warnings++;
                }
                else
                {
                    dis.State = CollectorState.Good;
                    success++;
                }
                string formatValue = FormatUtils.FormatFileSizePerSec(dis.NICInfo.RTxBytesPerSec);
                if (dis.AlertDefinition.PrimaryUIValue)
                {
                    currentState.CurrentValue     = formatValue.Split(' ')[0]; // (dis.NICInfo.RTxBytesPerSec/1024).ToString("0.00");
                    currentState.CurrentValueUnit = formatValue.Split(' ')[1]; //"kB/s";
                }

                MonitorState diskIOState = new MonitorState()
                {
                    ForAgent         = dis.NICInfo.Name,
                    State            = dis.State,
                    CurrentValue     = formatValue.Split(' ')[0], // (dis.NICInfo.RTxBytesPerSec / 1024).ToString("0.00"),
                    CurrentValueUnit = formatValue.Split(' ')[1], //"kB/s",
                    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];            // ((average/1024 )/ currentState.ChildStates.Count).ToString("0.00");
                currentState.CurrentValueUnit = formatValue.Split(' ')[1] + " (avg)"; // "kB/s (avg)";
            }

            return(currentState);
        }
Exemple #2
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);
        }