USE [HCITools] GO /****** Object: StoredProcedure [dbo].[mon_Check_Performance_Issue] Script Date: 11/09/2018 10:48:38 ******/ IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[mon_Check_Performance_Issue]') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].[mon_Check_Performance_Issue] GO USE [HCITools] GO /****** Object: StoredProcedure [dbo].[mon_Check_Performance_Issue] Script Date: 11/09/2018 10:48:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[mon_Check_Performance_Issue] @in_debug tinyint = 0, @in_NbHours tinyint = 3 AS /*============================================================================= Explication du traitement realise par la SP ------------------------------------------- La SP va check un ensemble de point de performance sur l'instance Contexte d'utilisation ---------------------- Appelé depuis le job DR92180 - Check Performance Issue Parametres ---------- @in_debug : non utilisé @in_NbHours : plage horaire d'analyse en heure Creation : 09.11.18 / FLA Modifications : 12.11.18 / FLA Correction envoi de mail avec message d'erreur 17.03.22 / FLA Change DBA mail 07.04.22 / RTC optimize perf =============================================================================*/ set nocount on; /*------------------- Declaration des variables --------------------*/ declare @PLE int, @NbCount smallint, @messageError varchar (8000), @errno int, @errmsg varchar(255), @ou_code varchar (15) /*------------ Affectation des parametres aux variables ------------*/ select @errno = 0 SET @messageError = '' SET @errmsg = '' /*-------------------------- Traitement ---------------------------*/ BEGIN TRY select @ou_code = ou.OU_code from Arizona.dbo.Bmc_application_key bapk with (nolock) join Arizona.dbo.Bmc_application_default bapd with (nolock) on bapd.BAPD_bmc_application_key = bapk.Bmc_application_key_ID join Arizona.dbo.Organizational_unit ou with (nolock) on convert (varchar, ou.organizational_unit_id) = bapd.BAPD_value where bapk.BAPK_key = 'cvCurrentOrganizationalUnit' /* RETRIEVE HH:MI OF WORKING HOURS */ declare @Hour_start varchar (5), @Hour_end varchar (5) ; select @Hour_start = isnull(dwoho.DWOHO_start_time_earliest, '07:00'), @Hour_end = isnull(dwoho.DWOHO_end_time_latest, '21:00') from Arizona.dbo.DBA_Working_hours dwoho with (nolock) join Arizona.dbo.Organizational_unit ou with (nolock) on ou.Organizational_unit_id = dwoho.DWOHO_organizational_unit where ou.ou_code = @ou_code ; select @PLE = CAST((CAST([value_in_use] AS INT) / 1024.0) / 4.0 * 300.0 AS INT) from sys.configurations WHERE name = 'max server memory (MB)' select @NbCount = COUNT(*) from dbo.Monitoring_counter MC inner join dbo.Monitoring_history MH ON MH.MH_monitoring_counter = MC.Monitoring_counter_ID where MC_name = 'Free list stalls/sec' AND MH_datetime >= DATEADD(hour,-@in_NbHours,GETDATE()) AND MH_value >= 2 AND MH_datetime >= @Hour_start AND MH_datetime <= @Hour_end IF @NbCount > 5 SET @messageError = @messageError + 'WARNING Free list stalls/sec'+CHAR(13)+CHAR(10) select @NbCount = COUNT(*) from dbo.Monitoring_counter MC inner join dbo.Monitoring_history MH ON MH.MH_monitoring_counter = MC.Monitoring_counter_ID where MC_name = 'Lazy writes/sec' AND MH_datetime >= DATEADD(hour,-@in_NbHours,GETDATE()) AND MH_value >= 20 AND MH_datetime >= @Hour_start AND MH_datetime <= @Hour_end IF @NbCount > 5 SET @messageError = @messageError + 'WARNING Lazy writes/sec'+CHAR(13)+CHAR(10) select @NbCount = COUNT(*) from dbo.Monitoring_counter MC inner join dbo.Monitoring_history MH ON MH.MH_monitoring_counter = MC.Monitoring_counter_ID where MC_name = 'Page reads/sec' AND MH_datetime >= DATEADD(hour,-@in_NbHours,GETDATE()) AND MH_value >= 90 AND MH_datetime >= @Hour_start AND MH_datetime <= @Hour_end IF @NbCount > 15 SET @messageError = @messageError + 'WARNING Page reads/sec'+CHAR(13)+CHAR(10) select @NbCount = COUNT(*) from dbo.Monitoring_counter MC inner join dbo.Monitoring_history MH ON MH.MH_monitoring_counter = MC.Monitoring_counter_ID where MC_name = 'Page life expectancy' AND MH_datetime >= DATEADD(hour,-@in_NbHours,GETDATE()) AND MH_value <= @PLE AND MH_datetime >= @Hour_start AND MH_datetime <= @Hour_end IF @NbCount > 20 SET @messageError = @messageError + 'WARNING Page life expectancy'+CHAR(13)+CHAR(10) select @NbCount = COUNT(*) from dbo.Monitoring_counter MC inner join dbo.Monitoring_history MH ON MH.MH_monitoring_counter = MC.Monitoring_counter_ID where MC_name = 'Memory Grants Pending' AND MH_datetime >= DATEADD(hour,-@in_NbHours,GETDATE()) AND MH_value >= 1 AND MH_datetime >= @Hour_start AND MH_datetime <= @Hour_end IF @NbCount > 5 SET @messageError = @messageError + 'WARNING Memory Grants Pending'+CHAR(13)+CHAR(10) IF @messageError <> '' BEGIN exec aps_Send_Mail_with_template @in_param_varchar_2 = 'DBA_operator;', @in_job_type = 3, /* 3 = warning */ @in_param_varchar_3 = @messageError END /*---------------------- Traitement des erreurs ----------------------*/ END TRY BEGIN CATCH /* Traitement des erreurs (avec RaiseError) */ EXEC dbo.get_Error_Info @in_RaiseError = 1 END CATCH GO