This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

95:th percentile aggregation?

We want to calculate 95:th percentile on aggregated interfaces. This is not a feature in orion so one of our devs wrote a query in report writer to sort it out.

Note that we also separate incoming and outgoing traffic

The problem is that i´m not sure if it´s presenting us with the correct values..

Any input on the query is much appreciated.

Right now we input the id´s of the interfaces that we want to sum up.

Here´s the query:

 

DECLARE @StartDate DateTime

DECLARE @EndDate DateTime

 

SET @StartDate = DATEADD(d, DATEDIFF(d, 0, DATEADD(m, -1, DATEADD(d, 1- day(getdate()), getdate()))), 0)

SET @EndDate = DATEADD(ms, -2,DATEADD(d, DATEDIFF(d, 0, DATEADD(d, 1 - day(getdate()), getdate())), 0))

 

create table #traffic_in (id bigint identity, bps bigint, ts datetime)

create table #traffic_out (id bigint identity, bps bigint, ts datetime)

insert into #traffic_in (bps, ts) SELECT sum(In_Maxbps), DateTime FROM dbo.InterfaceTraffic_Hourly_View WHERE InterfaceID in(3919, 3921, 3883, 3887) AND DateTime >= @StartDate AND DateTime <= @EndDate group by DateTime

insert into #traffic_out (bps, ts) SELECT sum(Out_Maxbps), DateTime FROM dbo.InterfaceTraffic_Hourly_View WHERE InterfaceID in(3919, 3921, 3883, 3887) AND DateTime >= @StartDate AND DateTime <= @EndDate group by DateTime

 

delete from #traffic_in where id in(select TOP 5 PERCENT id from #traffic_in order by bps desc)

delete from #traffic_out where id in(select TOP 5 PERCENT id from #traffic_out order by bps desc)

 

select 'In' as Riktning, convert(DECIMAL(12, 2), max(bps) / 1000.0 / 1000.0) as 'Mbit/s' from #traffic_in

union

select 'Out' as Riktning, convert(DECIMAL(12, 2), max(bps) / 1000.0 / 1000.0) as 'Mbit/s' from #traffic_out

 

Drop table #traffic_in

drop table #traffic_out

  • I'm no SQL guru but it loks like you are doing the right thing. One note is that the definition of 95th percentile is the point where 95% of the traffic is at or below that level. Depending on if you are rounding, tossing the top 5% may not be the right thing. if you are taking traffic as collected and not rounding this will be OK.

  • It looks like it would sum, then knock any decimals off when it inserts (after math is done), if you changed the table creates to:

    create table #traffic_in (id bigint identity, bps real, ts datetime)
    create table #traffic_out (id bigint identity, bps real, ts datetime)

    Then there won't be any rounding/data conversion because that is the data source's format (there might not be any decimal places in the data, and then it wouldn't matter, but thats just looking at from the query and table design not the data in the table).

  • So the net effect then would be to provide something that is actually > 95th percentile by not including data at the 95%.