/*------------------------------------------------------------------------------------------------------------ 02/20/2009 This script captures CPU Utilization Percent using TSQL. It uses system functions @@CPU_BUSY and @@IDLE to see what is the CPU Utilization % at a particular instant. You can then use this number in a table or variable to trigger other events. @@CPU_BUSY shows the time SQL Server has been busy @@IDLE shows the time SQL Server has been idle ------------------------------------------------------------------------------------------------------------*/ DECLARE @CPU_BUSY int DECLARE @IDLE int SELECT @CPU_BUSY = @@CPU_BUSY, @IDLE = @@IDLE WAITFOR DELAY '000:00:01' SELECT (@@CPU_BUSY - @CPU_BUSY)/((@@IDLE - @IDLE + @@CPU_BUSY - @CPU_BUSY) * 1.00) *100 AS CPU_Utilization_Pct /* Compiled by http://www.learningsqlserver2008.com/, Kash Data Consulting LLC Disclaimer: All sample code and scripts are compiled by Kash Data Consulting LLC for illustrative purposes only. Kash Data Consulting LLC, therefore, cannot guarantee or imply reliability, or function of this code or scripts. All code contained herein are provided to you "AS IS" without any warranties of any kind. Please test all code and scripts in test environment before deployment in production systems. */