Query help

  • Hi friends,

    When I run the below procedure am getting as CPU utilization of the server is 185% ,300%. Where am I wrong in the script..

    create procedure CPU

    as

    begin

    declare @a as bigint, @b-2 as bigint, @val float

    select @a=sum(cntr_value)

    from sys.dm_os_performance_counters

    where object_name = 'SQLServer:Resource Pool Stats' and cntr_type = 537003264

    select distinct @b-2=cntr_value

    from sys.dm_os_performance_counters

    where object_name = 'SQLServer:Resource Pool Stats' and cntr_type = 1073939712

    set @val=(select cast(@a as float) / cast(@b as float)*100 as [cpu])

    print @val

    declare @temp varchar(max)

    set @temp='CPU utilization of server is '+CONVERT(VARCHAR(3),LEFT(@val,3))+'%'+' Check what is running in the server'

    if(@val>50)

    BEGIN

    Exec msdb.dbo.sp_send_dbmail

    @recipients='isdm@plintron.com',

    @subject='Server utilization is high',

    @body=@temp

    END

    end

    Thanks in advance.

  • Try this:

    set @val=(select cast(@a as float)*100 / cast(@b as float) as [cpu])

    Sundar, It's giving result correctly to me.

  • It seams to be working correctly for me as well...

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply