From ab98fc11168b800ba9c0a192f433ddf4b86843a9 Mon Sep 17 00:00:00 2001 From: Barry O'Donovan Date: Sun, 14 Nov 2021 11:16:40 +0000 Subject: [PATCH] [IM] Dashbord accounts for rate limited ports. --- app/Http/Controllers/AdminController.php | 42 ++++++++++--- .../VirtualInterfaceAggregator.php | 1 + resources/views/admin/dashboard.foil.php | 60 +++++++++++++++++++ 3 files changed, 94 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index c17c618ff..0e236805a 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -35,6 +35,7 @@ Customer, Infrastructure, Location, + PhysicalInterface, Vlan, VlanInterface}; @@ -100,6 +101,11 @@ private function dashboardStats( Request $r ): array $custsByInfra = []; $peeringCusts = []; + // for rate limited ports: + $rateLimitedPorts = []; + $pispeeds = PhysicalInterface::$SPEED; + krsort( $pispeeds, SORT_NUMERIC ); + foreach( $vis as $vi ) { $location = $vi[ 'locationname' ]; @@ -132,10 +138,27 @@ private function dashboardStats( Request $r ): array $custsByLocation[ $location ]['cabinets'][$cabinet][ 'custs' ][] = $custid; } - if ( !isset($speeds[ $vi[ 'speed' ] ])) { - $speeds[ $vi[ 'speed' ] ] = 1; + // Speeds have gotten more complex now that we've add rate limiters, sigh. + // We're not going to go around the houses here to solve odd services - speeds + // should be a multiple of physical speeds. + $speed = $vi[ 'speed' ]; + $numports = 1; + + if( $vi[ 'rlspeed' ] ) { + foreach( array_keys( $pispeeds ) as $kspeed ) { + if( $vi[ 'rlspeed' ] >= $kspeed ) { + $speed = $kspeed; + $numports = round( $vi[ 'rlspeed' ] / $kspeed ); + $rateLimitedPorts[] = [ 'physint' => $vi['speed'], 'numports' => $numports, 'rlspeed' => $speed ]; + break; + } + } + } + + if ( !isset($speeds[ $speed ])) { + $speeds[ $speed ] = $numports; } else { - $speeds[ $vi[ 'speed' ] ]++; + $speeds[ $speed ] += $numports; } if ( !isset($custsByInfra[ $infrastructure ])) { @@ -159,10 +182,10 @@ private function dashboardStats( Request $r ): array $byLocation[ $location ]['cabinets'][ $cabinet ] = [ 'id' => $vi[ 'cabinetid' ] ]; } - if ( !isset($byLocation[ $vi[ 'locationname' ] ][ $vi[ 'speed' ] ])) { - $byLocation[ $location ][ $vi[ 'speed' ] ] = 1; + if ( !isset($byLocation[ $vi[ 'locationname' ] ][ $speed ])) { + $byLocation[ $location ][ $speed ] = $numports; } else { - $byLocation[ $location ][ $vi[ 'speed' ] ]++; + $byLocation[ $location ][ $speed ] += $numports; } if ( !isset($byLocation[ $location ]['cabinets'][ $cabinet ][ $vi[ 'speed' ] ])) { @@ -175,10 +198,10 @@ private function dashboardStats( Request $r ): array $byLan[ $infrastructure ] = [ 'id' => $vi[ 'infrastructureid' ] ]; } - if ( !isset( $byLan[ $infrastructure ][ $vi[ 'speed' ] ] ) ) { - $byLan[ $infrastructure ][ $vi[ 'speed' ] ] = 1; + if ( !isset( $byLan[ $infrastructure ][ $speed ] ) ) { + $byLan[ $infrastructure ][ $speed ] = $numports; } else { - $byLan[ $infrastructure ][ $vi[ 'speed' ] ]++; + $byLan[ $infrastructure ][ $speed ] += $numports; } } @@ -195,6 +218,7 @@ private function dashboardStats( Request $r ): array $cTypes[ 'byIxp' ] = $byIxp; $cTypes[ 'custsByInfra' ] = $custsByInfra; $cTypes[ 'peeringCusts' ] = $peeringCusts; + $cTypes[ 'rateLimitedPorts' ] = $rateLimitedPorts; // FROM of query is vlaninterface so should be current: $cTypes[ 'usage' ] = VlanInterface::selectRaw( diff --git a/app/Models/Aggregators/VirtualInterfaceAggregator.php b/app/Models/Aggregators/VirtualInterfaceAggregator.php index bc51a16e2..e4e7688ec 100644 --- a/app/Models/Aggregators/VirtualInterfaceAggregator.php +++ b/app/Models/Aggregators/VirtualInterfaceAggregator.php @@ -128,6 +128,7 @@ public static function getByLocation(): array 'cust.id AS customerid', 'vi.id AS id', 'pi.speed AS speed', + 'pi.rate_limit AS rlspeed', 'i.id AS infrastructureid', 'i.name AS infrastructure', 'l.id AS locationid', diff --git a/resources/views/admin/dashboard.foil.php b/resources/views/admin/dashboard.foil.php index 74f50f3f1..14c8b8273 100644 --- a/resources/views/admin/dashboard.foil.php +++ b/resources/views/admin/dashboard.foil.php @@ -195,6 +195,17 @@ + + stats[ "rateLimitedPorts" ] ) ): ?> +

+ These statistics take account of rate limited / partial speed ports. See + here for details. + +

+ + + + @@ -528,6 +539,55 @@ + stats[ "rateLimitedPorts" ] ) ): ?> +
+

+ Rate Limited / Partial Speed Ports +

+ +

+ The above statistics take account of the following rate limited ports. By take account of we + mean that if a 10Gb port is rate limited as 2Gb then the above statistics reflect it as 2 x 1Gb + ports and the 10Gb is ignored. +

+ + + + + + + + + + + + stats[ "rateLimitedPorts"] as $rateLimitedPorts => $rlp ): ?> + + + + + + + + +
+ Physical Port Speed + + Rate Limit + + Account For As +
+ scaleSpeed( $rlp['physint']) ?> + + scaleSpeed( $rlp['numports'] * $rlp['rlspeed'] ) ?> + + x scaleSpeed( $rlp['rlspeed']) ?> +
+
+ + + +