Наследование: System.EventArgs
Пример #1
0
        public void CheckPerformance()
        {
            try
            {
                if (RequestPerformanceServer != null)
                {
                    var e = new ServerInfoEventArgs();
                    RequestPerformanceServer(this, e);
                    if (!e.Cancel)
                    {
                        Instance.AddUserPerformanceItem(e.Server, e.IsServer);
                        CheckPerformanceItem(e.Server, e.IsServer);
                    }
                }

                if (this.Equals(Instance))
                {
                    Settings.Instance.PerformanceItems.ForEach(i =>
                    {
                        var exists = Instance._userPerformanceItems.Exists(p => p.Server == i.Server &&
                                                                           p.Database == i.Database && p.IsServer == i.IsServer);
                        if (!exists)
                        {
                            CheckPerformanceItem(i, i.IsServer);
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
        }
Пример #2
0
 private void OnMonitorEngineRequestServer(object sender, ServerInfoEventArgs e)
 {
     e.IsServer = _objectMode == ObjectModes.Server;
     e.Server = _server;
     e.Cancel = _server == null;
 }
Пример #3
0
        public void CheckServerHealth()
        {
            if (RequestHealthServer != null && Health != null)
            {
                var e = new ServerInfoEventArgs();
                RequestHealthServer(this, e);
                var healthItems = new List<HealthItem>();
                if (!e.Cancel && e.Server != null && !string.IsNullOrEmpty(e.Server.Server))
                {
                    var isValid = true;
                    try
                    {
                        var version = QueryEngine.GetServerVersion(e.Server);
                    }
                    catch (Exception)
                    {
                        isValid = false;
                    }
                    if (isValid)
                    {
                        var isAlert = false;

                        //memory
                        long physicalMemory;
                        long availableMemory;
                        var serverState = e.Server as ServerState;
                        if (!serverState.IsAzure)
                            QueryEngine.GetMemoryInfo(e.Server, out physicalMemory, out availableMemory);
                        else
                        {
                            physicalMemory = 0;
                            availableMemory = 0;
                        }
                        var memoryMb = SqlHelper.ExecuteScalar("SELECT (cntr_value/1024.0) FROM sys.dm_os_performance_counters WHERE counter_name = 'Total Server Memory (KB)'", e.Server);
                        if (memoryMb != null)
                        {
                            var memory = Convert.ToInt32(memoryMb);
                            isAlert = availableMemory * 1.0 / physicalMemory < Settings.Instance.FreeMemoryRatio / 100.0;
                            healthItems.Add(new HealthItem { Category = HealthCategoryServer, HealthType = HealthTypes.ServerMemory, CurrentValue = availableMemory.ToString() + " " + Utils.SizeMb, ReferenceValue = memory + " " + Utils.SizeMb, ItemName = "Server Memory", Description = "Free/DB Used", IsAlert = isAlert });
                        }

                        //cpu
                        int cpuSqlProcess;
                        int cpuSystemIdle;
                        int cpuOtherProcesses;
                        QueryEngine.GetCpuInfo(e.Server, out cpuSqlProcess, out cpuSystemIdle, out cpuOtherProcesses);
                        isAlert = cpuSystemIdle < Settings.Instance.FreeCpuRatio;
                        healthItems.Add(new HealthItem { Category = HealthCategoryServer, HealthType = HealthTypes.ServerCpu, CurrentValue = cpuSystemIdle.ToString() + " %", ReferenceValue = cpuSqlProcess + " %", ItemName = "Server CPU", Description = "Free/DB Used", IsAlert = isAlert });

                        //disk space
                        var diskSpaces = QueryEngine.GetDiskSpace(e.Server);
                        diskSpaces.Where(s => s.Value.Value > 0).ForEach(s =>
                        {
                            isAlert = s.Value.Key < s.Value.Value / 100 * Settings.Instance.DatabaseDiskFreeSpaceRatio;
                            healthItems.Add(new HealthItem { Category = HealthCategoryServer, HealthType = HealthTypes.ServerSpace, CurrentValue = s.Value.Key.ToString() + " " + Utils.SizeMb, ReferenceValue = s.Value.Value + " " + Utils.SizeMb, ItemName = "Disk Space (" + s.Key + ")", Description = "Free/DB Used", IsAlert = isAlert });
                        });

                        if (!e.Server.IsAzure)
                        {
                            //locked objects
                            var lockedObjects = SqlHelper.Query(QueryEngine.SqlLockedObjects, e.Server);
                            lockedObjects.Rows.Cast<DataRow>().ForEach(r =>
                            {
                                isAlert = false;
                                healthItems.Add(new HealthItem { Category = HealthCategoryProcess, HealthType = HealthTypes.LockedObjects, CurrentValue = r.Field<string>("SchemaName") + "." + r.Field<string>("ObjectName"), ReferenceValue = r.Field<string>("DatabaseName"), ItemName = "Locked Object", Description = r.Field<string>("ProgramName"), IsAlert = isAlert });
                            });
                        }

                        //blocked processes
                        var blockedProcesses = SqlHelper.Query(QueryEngine.SqlWaitingTasks + " WHERE blocking_session_id IS NOT NULL", e.Server);
                        blockedProcesses.Rows.Cast<DataRow>().ForEach(r =>
                        {
                            isAlert = true;
                            healthItems.Add(new HealthItem { Category = HealthCategoryProcess, HealthType = HealthTypes.BlockedProcess, CurrentValue = r["Session Id"].ToString(), ReferenceValue = r["Blocking Session Id"].ToString(), ItemName = "Blocked Process", Description = "Blocked/Blocking", IsAlert = isAlert });
                        });

                        //db performance
                        var databaseStalls = QueryEngine.GetDatabaseStall(e.Server);
                        databaseStalls.ForEach(db =>
                        {
                            isAlert = db.IsExceeded;
                            healthItems.Add(new HealthItem { Category = HealthCategoryDatabase, HealthType = HealthTypes.DatabaseStall, CurrentValue = db.Max + " " + Utils.TimeMs, ReferenceValue = QueryEngine.DbStallThreshold + " " + Utils.TimeMs, ItemName = "DB Perf (" + db.Database + ")", Description = "Higher = worse", IsAlert = isAlert });
                        });

                        //db/log space
                        var dbLogSpaces = QueryEngine.GetDbLogSpace(e.Server);
                        dbLogSpaces.Where(s => !s.Value.Item3).ForEach(s =>
                        {
                            healthItems.Add(new HealthItem { Category = HealthCategoryDatabase, HealthType = HealthTypes.DatabaseLogSpace, CurrentValue = s.Value.Item1.ToString() + " " + Utils.SizeMb, ReferenceValue = s.Value.Item2 + " " + Utils.SizeMb, ItemName = "DB/Log Space (" + s.Key + ")", Description = "Log/DB", IsAlert = true });
                        });
                    }
                }
                Health(this, new HealthEventArgs { Result = healthItems });
            }
        }
Пример #4
0
        public void CheckPerformance()
        {
            try
            {
                if (RequestPerformanceServer != null)
                {
                    var e = new ServerInfoEventArgs();
                    RequestPerformanceServer(this, e);
                    if (!e.Cancel)
                    {
                        Instance.AddUserPerformanceItem(e.Server, e.IsServer);
                        CheckPerformanceItem(e.Server, e.IsServer);
                    }
                }

                if (this.Equals(Instance))
                {
                    Settings.Instance.PerformanceItems.ForEach(i =>
                        {
                            var exists = Instance._userPerformanceItems.Exists(p => p.Server == i.Server
                                && p.Database == i.Database && p.IsServer == i.IsServer);
                            if (!exists)
                                CheckPerformanceItem(i, i.IsServer);
                        });
                }
            }
            catch (Exception ex)
            {
                OnError(ex);
            }
        }
Пример #5
0
        public void CheckServerHealth()
        {
            if (RequestHealthServer != null && Health != null)
            {
                var e = new ServerInfoEventArgs();
                RequestHealthServer(this, e);
                var healthItems = new List <HealthItem>();
                if (!e.Cancel && e.Server != null && !string.IsNullOrEmpty(e.Server.Server))
                {
                    var isValid = true;
                    try
                    {
                        var version = QueryEngine.GetServerVersion(e.Server);
                    }
                    catch (Exception)
                    {
                        isValid = false;
                    }
                    if (isValid)
                    {
                        var isAlert = false;

                        //memory
                        long physicalMemory;
                        long availableMemory;
                        var  serverState = e.Server as ServerState;
                        if (!serverState.IsAzure)
                        {
                            QueryEngine.GetMemoryInfo(e.Server, out physicalMemory, out availableMemory);
                        }
                        else
                        {
                            physicalMemory  = 0;
                            availableMemory = 0;
                        }
                        var memoryMb = SqlHelper.ExecuteScalar("SELECT (cntr_value/1024.0) FROM sys.dm_os_performance_counters WHERE counter_name = 'Total Server Memory (KB)'", e.Server);
                        if (memoryMb != null)
                        {
                            var memory = Convert.ToInt32(memoryMb);
                            isAlert = availableMemory * 1.0 / physicalMemory < Settings.Instance.FreeMemoryRatio / 100.0;
                            healthItems.Add(new HealthItem {
                                Category = HealthCategoryServer, HealthType = HealthTypes.ServerMemory, CurrentValue = availableMemory.ToString() + " " + Utils.SizeMb, ReferenceValue = memory + " " + Utils.SizeMb, ItemName = "Server Memory", Description = "Free/DB Used", IsAlert = isAlert
                            });
                        }

                        //cpu
                        int cpuSqlProcess;
                        int cpuSystemIdle;
                        int cpuOtherProcesses;
                        QueryEngine.GetCpuInfo(e.Server, out cpuSqlProcess, out cpuSystemIdle, out cpuOtherProcesses);
                        isAlert = cpuSystemIdle < Settings.Instance.FreeCpuRatio;
                        healthItems.Add(new HealthItem {
                            Category = HealthCategoryServer, HealthType = HealthTypes.ServerCpu, CurrentValue = cpuSystemIdle.ToString() + " %", ReferenceValue = cpuSqlProcess + " %", ItemName = "Server CPU", Description = "Free/DB Used", IsAlert = isAlert
                        });

                        //disk space
                        var diskSpaces = QueryEngine.GetDiskSpace(e.Server);
                        diskSpaces.Where(s => s.Value.Value > 0).ForEach(s =>
                        {
                            isAlert = s.Value.Key < s.Value.Value / 100 * Settings.Instance.DatabaseDiskFreeSpaceRatio;
                            healthItems.Add(new HealthItem {
                                Category = HealthCategoryServer, HealthType = HealthTypes.ServerSpace, CurrentValue = s.Value.Key.ToString() + " " + Utils.SizeMb, ReferenceValue = s.Value.Value + " " + Utils.SizeMb, ItemName = "Disk Space (" + s.Key + ")", Description = "Free/DB Used", IsAlert = isAlert
                            });
                        });

                        if (!e.Server.IsAzure)
                        {
                            //locked objects
                            var lockedObjects = SqlHelper.Query(QueryEngine.SqlLockedObjects, e.Server);
                            lockedObjects.Rows.Cast <DataRow>().ForEach(r =>
                            {
                                isAlert = false;
                                healthItems.Add(new HealthItem {
                                    Category = HealthCategoryProcess, HealthType = HealthTypes.LockedObjects, CurrentValue = r.Field <string>("SchemaName") + "." + r.Field <string>("ObjectName"), ReferenceValue = r.Field <string>("DatabaseName"), ItemName = "Locked Object", Description = r.Field <string>("ProgramName"), IsAlert = isAlert
                                });
                            });
                        }

                        //blocked processes
                        var blockedProcesses = SqlHelper.Query(QueryEngine.SqlWaitingTasks + " WHERE blocking_session_id IS NOT NULL", e.Server);
                        blockedProcesses.Rows.Cast <DataRow>().ForEach(r =>
                        {
                            isAlert = true;
                            healthItems.Add(new HealthItem {
                                Category = HealthCategoryProcess, HealthType = HealthTypes.BlockedProcess, CurrentValue = r["Session Id"].ToString(), ReferenceValue = r["Blocking Session Id"].ToString(), ItemName = "Blocked Process", Description = "Blocked/Blocking", IsAlert = isAlert
                            });
                        });

                        //db performance
                        var databaseStalls = QueryEngine.GetDatabaseStall(e.Server);
                        databaseStalls.ForEach(db =>
                        {
                            isAlert = db.IsExceeded;
                            healthItems.Add(new HealthItem {
                                Category = HealthCategoryDatabase, HealthType = HealthTypes.DatabaseStall, CurrentValue = db.Max + " " + Utils.TimeMs, ReferenceValue = QueryEngine.DbStallThreshold + " " + Utils.TimeMs, ItemName = "DB Perf (" + db.Database + ")", Description = "Higher = worse", IsAlert = isAlert
                            });
                        });

                        //db/log space
                        var dbLogSpaces = QueryEngine.GetDbLogSpace(e.Server);
                        dbLogSpaces.Where(s => !s.Value.Item3).ForEach(s =>
                        {
                            healthItems.Add(new HealthItem {
                                Category = HealthCategoryDatabase, HealthType = HealthTypes.DatabaseLogSpace, CurrentValue = s.Value.Item1.ToString() + " " + Utils.SizeMb, ReferenceValue = s.Value.Item2 + " " + Utils.SizeMb, ItemName = "DB/Log Space (" + s.Key + ")", Description = "Log/DB", IsAlert = true
                            });
                        });
                    }
                }
                Health(this, new HealthEventArgs {
                    Result = healthItems
                });
            }
        }