dbTalk Databases Forums  

Script for SQL Agent "Weighted Job Duration"

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Script for SQL Agent "Weighted Job Duration" in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Louis
 
Posts: n/a

Default Script for SQL Agent "Weighted Job Duration" - 07-20-2004 , 10:54 AM






Hi,

Does anyone know of a script that will give "weighted job duration"?
I want to use it, to identify which jobs are hogging the CPU. That is
for a given server, list the sql agent jobs ordered by:

(avg job duration in minutes) times (avg num of times job runs in a
given day).

Reply With Quote
  #2  
Old   
Ross Presser
 
Posts: n/a

Default Re: Script for SQL Agent "Weighted Job Duration" - 07-20-2004 , 12:08 PM






On 20 Jul 2004 08:54:48 -0700, Louis wrote:

Quote:
Hi,

Does anyone know of a script that will give "weighted job duration"?
I want to use it, to identify which jobs are hogging the CPU. That is
for a given server, list the sql agent jobs ordered by:

(avg job duration in minutes) times (avg num of times job runs in a
given day).
Assuming SQL Server 2000 or higher, I came up with this:

Select T3.name, avg(T3.Recurrences) 'AvgRecurrencesPerDay',
sum(T3.[TotalDailyDuration])/sum(T3.Recurrences) 'AvgDuration',
avg(T3.Recurrences) * sum(T3.TotalDailyDuration)/sum(T3.Recurrences)
'Weight'
from (
select T2.name, T1.run_date,
count(*) 'Recurrences',
sum(T1.run_duration) 'TotalDailyDuration'
from msdb.dbo.sysjobhistory T1
inner join msdbo.dbo.sysjobs T2 on T1.job_id = T2.job_id
group by T2.name, T1.run_date
) T3
group by T3.name
order by Weight desc, T3.Name asc


Reply With Quote
  #3  
Old   
louis
 
Posts: n/a

Default Re: Script for SQL Agent "Weighted Job Duration" - 07-20-2004 , 03:55 PM



Thanks Ross. I played with your script and altered it a bit. I decided
what I really want is avg minutes per day.
- Louis

SELECT name as Job,
str(occurrences/@numDays,10,1) as RunsPerDay,
str(duration/occurrences,10,1) as MinsPerJob,
str(duration/@numDays,10,1) as MinsPerDay
FROM (
SELECT T2.name,
cast(count(*) as dec) as occurrences,
cast(sum(
(run_duration / 100)/100*60 + (run_duration / 100)%100 --
run_duration is in hhmmss crazy format
) as dec) as duration
FROM msdb.dbo.sysjobhistory T1
INNER JOIN msdb.dbo.sysjobs T2
ON T1.job_id = T2.job_id and step_id=0
and cast(rtrim(T1.run_date) as datetime) between @startdate and
@enddate
GROUP BY T2.name
) T
ORDER BY MinsPerDay desc

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.