SQL Server Proactive Memory Monitoring and Alerting Setup
SQL Server Proactive Memory Monitoring and Alerting Setup
Objective
Implement a proactive monitoring and alerting solution for SQL Server that:
Monitoring Components
SELECT
(SELECT cntr_value FROM sys.dm_os_performance_counters
WHERE counter_name = 'Total Server Memory (KB)' AND object_name LIKE
'%Memory Manager%') AS TotalMemoryKB,
(SELECT cntr_value FROM sys.dm_os_performance_counters
WHERE counter_name = 'Target Server Memory (KB)' AND object_name LIKE
'%Memory Manager%') AS TargetMemoryKB;
SELECT TOP 5
session_id,
requested_memory_kb / 1024 AS RequestedMB,
granted_memory_kb / 1024 AS GrantedMB,
LEFT(text, 200) AS QueryText
FROM sys.dm_exec_query_memory_grants g
CROSS APPLY sys.dm_exec_sql_text(g.sql_handle)
ORDER BY requested_memory_kb DESC;
$total = $memory.TotalMemoryKB
$target = $memory.TargetMemoryKB
$percentUsed = [math]::Round(($total / $target) * 100, 2)
Deployment Options
Notes