My manager has asked me to work upon a request. I am not sure if it is reasonable or weird but he wants me to setup an alert based on the "waiting task" that we see in the activity monitor. Basically, if the value in the "waiting task" goes above 10 then we need to be alerted upon. I am not sure as to how I would replicate the same information that we see in Activity monitor as this seems to be live data. Closest DMV and the column I could think of is "waiting_tasks_count" in sys.dm_os_wait_stats. However, this does not seem to be in line with what he is looking for and the column consists of cumulative values over a period of time since last time SQL was restarted. Can someone shed some light on where I can find a query or a counter that I can alert upon?
I have thought about a query at this time but I think I can't calculate the delta correctly it always shows me 1. Can someone help me out exactly where I am going wrong here.
select so1.wait_type,
so1.waiting_tasks_count as no_of_waits,
so1.waiting_tasks_count - so2.waiting_tasks_count as delta_wait_count,
so1.signal_wait_time_ms,
so1.wait_time_ms - so2.signal_wait_time_ms as resource_wait_time,
getdate() as sample_time
from sys.dm_os_wait_stats as so1
inner join sys.dm_os_wait_stats as so2
on so2.waiting_tasks_count = so1.waiting_tasks_count - 1
Best Answer
you can trace out the exact query in profiler..below is the query you are referring to