I have been looking for a way to automatically create a report to easily determine the network link which need an upgrade.
The average or 95th are good but show their limits when it come to more isolated burst (which may generate impact on customer)
I added 2 variables : PCOT and ISLAND
PCOT = Polling cycle over threshold --> Quantity of polling cycle for which the utilization was >= 80%
In this example, the polling interval was every minute and the query keep only records between 8 and 16. So this is 14400 minutes.
The ISLAND is the quantity of time that there was a contiguous utilization >= 80%
This query run in 7min on 1812 interfaces, polling every minutes, details stats for 1 month.
I'm sure this query can be optimized because I barely understand what I do in SQL
I don't want any lesson of SQL here. If you think you can do better, just post it!
If you can optimize it, you will have my eternal gratitude
It serve his purpose in my company, I'm just posting it so that other can use it / contribute.
* I started to build the query based on another script on Thawk for the 95th percentile, so some variable have the same name.
*** QUERY UPDATED 2018-09-04 ***
Added SET DATEFIRST 7
DECLARE@StartBusinessHoursFLOAT
DECLARE@EndBusinessHoursFLOAT
DECLARE@ThresholdFLOAT
DECLARE@PollingIntervalFLOAT
DECLARE@DaysFLOAT
SET@StartBusinessHours=8
SET@EndBusinessHours=16
SET@Threshold=80
SET@PollingInterval=1
SET@Days=30
SET DATEFIRST 7
SELECTDISTINCTSecondSet.interfaceid ASINTERFACEID,
FourthSet.caption ASNOM_SITE,
SecondSet.caption ASNOM_INTERFACE,
ThirdSet.nb_island ASNB_ISLAND_GT_30,
MOY_MAX=CASE
WHENSecondset.avg_in_percent>
Secondset.avg_out_percentTHEN
Secondset.avg_in_percent
ELSESecondset.avg_out_percent
END,
Firstset.pcot_percent ASPCOT80_POURCENT,
FirstSet.polling_cycle_over_thresholdASPCOT80,
Secondset.avg_in ASMOY_IN,
Secondset.avg_out ASMOY_OUT,
Secondset.avg_in_percent ASMOY_IN_POURCENT,
Secondset.avg_out_percent ASMOY_OUT_POURCENT,
Secondset.inbandwidth ASCAPACITE_IN,
Secondset.outbandwidth ASCAPACITE_OUT,
FifthSet.PRECISION
FROM (SELECTi.interfaceid,
Count(i.interfaceid)
ASPolling_Cycle_Over_Threshold,
Round(
(NULLIF(Count(i.interfaceid),0)/((24)*60*@Days))*100,2)
AS
PCOT_PERCENT
FROM [SURV_PRO_NPM].[dbo].[interfacetraffic_detail]ASIWITH(nolock)
INNERJOIN[SURV_PRO_NPM].[dbo].[interfaces]ASJWITH(nolock)
ON([I].interfaceid=[j].interfaceid)
WHERE (i.in_maxbps>=(NULLIF(J.inbandwidth,0)*@Threshold/100)
ORi.out_maxbps>=(
NULLIF(J.outbandwidth,0)*@Threshold/100))
AND((Datepart(dw,datetime))<>1
AND(Datepart(dw,datetime)<>7))
AND(Datepart(hh,datetime)>=@StartBusinessHours
AND(Datepart(hh,datetime)<=@EndBusinessHours))
GROUP BYi.interfaceid,
j.interfacename)ASFirstSet
FULLOUTERJOIN(SELECT
Avg(NULLIF(i.in_maxbps,0))
ASAVG_IN,
Avg(NULLIF(i.in_maxbps,0))/NULLIF(J.inbandwidth,0)*100 AS
AVG_IN_PERCENT
,
Avg(NULLIF(i.out_maxbps,0))
ASAVG_OUT,
Avg(NULLIF(i.out_maxbps,0))/NULLIF(J.outbandwidth,0)*100AS
AVG_OUT_PERCENT,
i.interfaceid,
i.nodeid,
j.caption,
J.inbandwidth,
J.outbandwidth
FROM [dbo].[interfacetraffic_detail]ASIWITH(nolock)
INNERJOIN[SURV_PRO_NPM].[dbo].[interfaces]ASJWITH(nolock)
ON([i].interfaceid=[j].interfaceid)
WHERE ((Datepart(dw,datetime))<>1
AND(Datepart(dw,datetime)<>7))
AND(Datepart(hh,datetime)>=@StartBusinessHours
AND(Datepart(hh,datetime)<=@EndBusinessHours))
GROUP BYi.interfaceid,
i.nodeid,
J.caption,
J.outbandwidth,
J.inbandwidth)ASSecondSet
ONFirstSet.interfaceid=SecondSet.interfaceid
FULLOUTERJOIN(SELECTCount(*)ASNB_ISLAND,
interface_id
FROM (SELECTCount(grp) ASNB_ISLAND,
interfaceidASINTERFACE_ID
FROM (SELECTDatediff(minute,'19000101',
i.datetime)
-Row_number()
OVER(
ORDERBYi.interfaceid,datetime)
ASGRP,
i.interfaceid,
i.datetime,
j.interfacename
FROM
[SURV_PRO_NPM].[dbo].[interfacetraffic_detail]AS
IWITH
(nolock
)
INNERJOIN[SURV_PRO_NPM].[dbo].[interfaces]ASJ
WITH(
nolock)
ON([i].interfaceid=[j].interfaceid)
WHERE (i.in_maxbps>=
(
NULLIF(J.inbandwidth,0)*@Threshold/100)
ORi.out_maxbps>=
(
NULLIF(J.outbandwidth,0)*@Threshold/100))
AND((Datepart(dw,datetime))<>1
AND(Datepart(dw,datetime)<>7
))
AND(Datepart(hh,datetime)>=
@StartBusinessHours
AND(Datepart(hh,datetime)<=
@EndBusinessHours
))
GROUP BYi.interfaceid,
j.interfacename,
i.datetime)ASSUB1
GROUP BYgrp,
interfaceid
HAVINGCount(grp)>=30)ASSUB2
GROUP BYinterface_id)ASThirdSet
ONFirstSet.interfaceid=ThirdSet.interface_id
INNERJOIN(SELECTn.nodeid,
n.caption
FROM nodesASNWITH(nolock))ASFourthSet
ONSecondSet.nodeid=FourthSet.nodeid
INNERJOIN(SELECTRound((Cast(Count(*)ASFLOAT)/44640)*100,-1)
AS
PRECISION,
I.interfaceid
FROM interfacetraffic_detailASIWITH(nolock)
GROUP BYinterfaceid)ASFifthSet
ONSecondSet.interfaceid=FifthSet.interfaceid
ORDER BYpolling_cycle_over_thresholdDESC