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' ls 2) withActiveJobCount ( nolock ) on ips.LocationID = ls.LocationID
inner join config.t_Serveraverage over 10 mins)' + char(13) + CHAR(13)
set @msg += N' Sample execution:' + char(13)
set @msg += N' srv with ( nolock ) on ls.ServerID declare @proejctId int = srv.ServerID1' + char(13)
leftset outer join@msg += N' exec history.ServerThroughput @proejctId' + char(13)
set @msg += N' '
SELECT raiserror (@msg, 0, 1) with nowait;
; with c_Jobs_Served as
j.ServerID (
,Count(j.JobID) cnt
SELECT
FROM jobs.t_job j with(nolockformat(StartDate, 'yyyy-MM-dd HH:00:00') GROUP BY ServerID as [Time]
) , NTILE(6) over(order by datepart(minute, StartDate)) as [servedtime_ntile]
, j.JobID
on ls.ServerID = [served].ServerID , ServerID
group by FROM jobs.t_job srv.Hostname ,srv.ServerID j with(nolock)
,ips.LocationID inner join jobs.t_JobLocationProjectIPRange jlr with(nolock) on ,[served].cnt
j.JobID = jlr.JobID
) where jlr.ProjectID = @ProjectId
-- Locations with multiple)
Servers
assigned , c_server_active_jobs as
-- Simply divide targets by Server count.(
, c_mult_server_per_loc as select
( sm.ServerID
select ,NTILE(6) over(order by datepart(minute, s.LocationIDsm.[Timestamp])) [time_ntile]
,countformat(ssm.ServerID) [servers_for_location]
[TimeStamp], 'yyyy-MM-dd HH:00:00') from c_serv [Timestamp]
s group by s,sm.LocationIDActiveJobCount
having count(s.ServerID) > 1from [config].[t_ServerMetric] sm
)
, c_res_server_active_jobs_summ as
(
select
aj.ServerID
,dateadd(minute, aj.time_ntile * 10, s.Hostnameaj.[Timestamp]) [Timestamp]
--,saj.ServerIDtime_ntile
,sumformat(avg(s.[servable_targets] / coalesce(sloc.servers_for_location, 1)) [servable_targets]
aj.ActiveJobCount * 1.0), 'N2') ,s.[complete_targets[ActiveJobCount]
from c_serv _server_active_jobs aj
group by
aj.ServerID
s left outer join c_mult_server_per_loc sloc on s.LocationID = sloc.LocationID,dateadd(minute, aj.time_ntile * 10, aj.[Timestamp])
)
group by select
s.Hostname js.ServerID
,s.ServerID ,dateadd(minute, js.[time_ntile] * 10, ,sjs.[complete_targetsTime]) [Time]
) ,count(js.JobID) [jobs_served]
insert into @ScanServerProgress ,aj.ActiveJobCount
select from c_Jobs_Served @ProjectID js
left outer join [ProjectID]
c_server_active_jobs_summ aj on js.ServerID = aj.ServerID
,rank() over (order by r.ServerID) [ServerID] ,r.Hostname and js.[Time] = aj.[server_name]Timestamp]
group by
,r.servable_targets js.ServerID
,r.complete_targets
,dateadd(minute, js.[time_ntile] * 10, js.[Time])
,cast(r.complete_targets * 100.00 / r.servable_targets as numeric ( 6, 2)) [complete_pct]aj.ActiveJobCount
order by
[Time]
from c_res r return,js.ServerID
end
go
|