create procedure history.ServerThroughput
@ProjectId int
with encryption
as
begin
set nocount on;
declare @msg nvarchar(2000) = N'Procedure name : history.ServerThroughput' + char(13)
set @msg += N' Returns scanning server activity per 10 minute interval.' + char(13)
set @msg += N' 1) Jobs Served. (total over 10 mins)' + char(13)
set @msg += N' 2) ActiveJobCount (average over 10 mins)' + char(13) + CHAR(13)
set @msg += N' Sample execution:' + char(13)
set @msg += N' declare @proejctId int = 1' + char(13)
set @msg += N' exec history.ServerThroughput @proejctId' + char(13)
set @msg += N' '
raiserror (@msg, 0, 1) with nowait;
; with c_Jobs_Served as
(
SELECT
format(StartDate, 'yyyy-MM-dd HH:00:00') as [Time]
, NTILE(6) over(order by datepart(minute, StartDate)) as [time_ntile]
, j.JobID
, ServerID
FROM jobs.t_job j with(nolock)
inner join jobs.t_JobLocationProjectIPRange jlr with(nolock) on j.JobID = jlr.JobID
where jlr.ProjectID = @ProjectId
)
, c_server_active_jobs as
(
select
sm.ServerID
,NTILE(6) over(order by datepart(minute, sm.[Timestamp])) [time_ntile]
,format(sm.[TimeStamp], 'yyyy-MM-dd HH:00:00') [Timestamp]
,sm.ActiveJobCount
from [config].[t_ServerMetric] sm
)
, c_server_active_jobs_summ as
(
select
aj.ServerID
,dateadd(minute, aj.time_ntile * 10, aj.[Timestamp]) [Timestamp]
--,aj.time_ntile
,format(avg(aj.ActiveJobCount * 1.0), 'N2') [ActiveJobCount]
from c_server_active_jobs aj
group by
aj.ServerID
,dateadd(minute, aj.time_ntile * 10, aj.[Timestamp])
)
select
js.ServerID
,dateadd(minute, js.[time_ntile] * 10, js.[Time]) [Time]
,count(js.JobID) [jobs_served]
,aj.ActiveJobCount
from c_Jobs_Served js
left outer join c_server_active_jobs_summ aj on js.ServerID = aj.ServerID
and js.[Time] = aj.[Timestamp]
group by
js.ServerID
,dateadd(minute, js.[time_ntile] * 10, js.[Time])
,aj.ActiveJobCount
order by
[Time]
,js.ServerID
end
go |