Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 268a461

Browse files
committed
WIP - Grapher latency graphs review
1 parent c891e7e commit 268a461

17 files changed

Lines changed: 110 additions & 296 deletions

File tree

app/Contracts/Grapher/Backend.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ public function isMultiFileConfigurationSupported(): bool;
100100
* For monolithic files, returns a single element array. Otherwise
101101
* an array keyed by the filename (with optional local directory path).
102102
*
103-
* @param IXP $ixp The IXP to generate the config for (multi-IXP mode)
104103
* @param int $type The type of configuration to generate
105104
* @return array
106105
*/
107-
public function generateConfiguration( IXP $ixp, int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array;
106+
public function generateConfiguration( int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array;
108107

109108
/**
110109
* Examines the provided graph object and determines if this backend is able to

app/Http/Controllers/Services/Grapher.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,11 @@ public function vlanInterface( Request $request ): Response {
169169
return $this->simpleResponse( $request );
170170
}
171171

172-
public function p2p( Request $request ): Response {
172+
public function latency( Request $request ): Response {
173173
return $this->simpleResponse( $request );
174174
}
175175

176-
public function smokeping( Request $request ): Response {
177-
176+
public function p2p( Request $request ): Response {
178177
return $this->simpleResponse( $request );
179178
}
180179
}

app/Http/Controllers/Services/Grapher/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function generateConfiguration( Request $request ): Response {
7676
abort( 404, "This backend ({$grapher->name()}) does not support single configuration files" );
7777
}
7878

79-
$config = $grapher->generateConfiguration( d2r( 'IXP' )->getDefault() )[0];
79+
$config = $grapher->generateConfiguration()[0];
8080

8181

8282
return (new Response( $config ) )

app/Http/Controllers/StatisticsController.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -384,17 +384,22 @@ public function memberDrilldown( StatisticsRequest $r, string $type, int $typeid
384384
}
385385

386386
/**
387+
* Show latency graphs
388+
*
387389
* @param Request $r
388390
* @param int $vliid
389391
* @return $this|RedirectResponse
390392
* @throws \IXP\Exceptions\Services\Grapher\ParameterException
393+
* @throws \Illuminate\Auth\Access\AuthorizationException
391394
*/
392-
public function smokeping( Request $r, int $vliid ){
395+
public function latency( Request $r, int $vliid ){
393396
/** @var VlanInterfaceEntity $vli */
394397
if( !( $vli = D2EM::getRepository( VlanInterfaceEntity::class )->find( $vliid ) ) ){
395-
abort( 404, 'Unknown vlan interface' );
398+
abort( 404, 'Unknown VLAN interface' );
396399
}
397400

401+
$graph = App::make('IXP\Services\Grapher')->latency( $vli );
402+
$graph->authorise();
398403

399404
$listProtocols = Graph::PROTOCOLS_REAL;
400405

@@ -403,43 +408,37 @@ public function smokeping( Request $r, int $vliid ){
403408
$enabled = 'get' . ucfirst( $p ) . 'enabled';
404409
$canping = 'get' . ucfirst( $p ) . 'canping';
405410

406-
if( !$vli->$enabled() || !$vli->$canping() )
411+
if( !$vli->$enabled() || !$vli->$canping() ) {
407412
unset( $listProtocols[ $p ] );
408-
}
409-
410-
411-
if( count( $listProtocols ) ) {
412-
$proto = $r->input( 'protocol' );
413-
414-
if( !in_array( $proto, array_keys( $listProtocols ) ) ){
415-
$proto = array_keys( $listProtocols )[0];
416413
}
414+
}
417415

418-
$ipfn = 'get' . $listProtocols[ $proto ] . 'Address';
419-
$ip = $vli->$ipfn()->getAddress();
420416

421-
} else {
417+
if( !count( $listProtocols ) ) {
422418
AlertContainer::push(
423-
"This customer does not have pinging enabled for any IP address(es) on the requested interface",
419+
"Protocol or ping not enabled on the requested interface",
424420
Alert::WARNING
425421
);
426422
return redirect()->to( route( "statistics@member" ), [ "id" => $vli->getVirtualInterface()->getCustomer()->getId() ] );
427423
}
428424

429-
$graph = App::make('IXP\Services\Grapher')->smokeping( $vli );
430425

431-
$graph->setProtocol( $proto );
426+
$proto = $r->input( 'protocol' );
427+
if( !in_array( $proto, array_keys( $listProtocols ) ) ){
428+
$proto = array_keys( $listProtocols )[0];
429+
}
432430

433-
$graph->authorise();
431+
$ipfn = 'get' . ucfirst( $listProtocols[ $proto ] ) . 'Address';
432+
$ip = $vli->$ipfn()->getAddress();
433+
434+
$graph->setProtocol( $proto );
434435

435-
return view( 'statistics/smokeping' )->with([
436+
return view( 'statistics/latency' )->with([
436437
'c' => $vli->getVirtualInterface()->getCustomer(),
437438
'vli' => $vli,
438439
'ip' => $ip,
439440
'protocol' => $proto,
440-
'grapher' => $graph,
441-
441+
'graph' => $graph,
442442
]);
443-
444443
}
445444
}

app/Http/Middleware/Services/Grapher.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
Customer as CustomerGraph, // member agg over all physical ports
4343
VlanInterface as VlanIntGraph, // member VLAN interface
4444
P2p as P2pGraph,
45-
Smokeping as SmokepingGraph
45+
Latency as LatencyGraph
4646
};
4747

4848

@@ -157,18 +157,19 @@ private function processParameters( Request $request, GrapherService $grapher ):
157157
$graph = $grapher->vlanint( $vlanint )->setParamsFromArray( $request->all() );
158158
break;
159159

160+
case 'latency':
161+
$vli = LatencyGraph::processParameterVlanInterface( (int)$request->input( 'id', 0 ) );
162+
$request->vli = $vli;
163+
$graph = $grapher->latency( $vli )->setParamsFromArray( $request->all() );
164+
break;
165+
160166
case 'p2p':
161167
$srcvlanint = P2pGraph::processParameterSourceVlanInterface( (int)$request->input( 'svli', 0 ) );
162168
$dstvlanint = P2pGraph::processParameterDestinationVlanInterface( (int)$request->input( 'dvli', 0 ) );
163169
$request->srcvlanint = $srcvlanint->getId();
164170
$request->dstvlanint = $dstvlanint->getId();
165171
$graph = $grapher->p2p( $srcvlanint, $dstvlanint )->setParamsFromArray( $request->all() );
166172
break;
167-
case 'smokeping':
168-
$vli = SmokepingGraph::processParameterVlanInterface( (int)$request->input( 'id', 0 ) );
169-
$request->vli = $vli;
170-
$graph = $grapher->smokeping( $vli )->setParamsFromArray( $request->all() );
171-
break;
172173

173174

174175
default:

app/Providers/GrapherServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function boot()
7474
Route::get( 'customer', 'Grapher@customer' ); // member agg over all physint's
7575
Route::get( 'vlaninterface', 'Grapher@vlanInterface' ); // member vlan interface
7676
Route::get( 'p2p', 'Grapher@p2p' ); // member vlan interface
77-
Route::get( 'smokeping', 'Grapher@smokeping' );
77+
Route::get( 'latency', 'Grapher@latency' );
7878
});
7979

8080
Route::group(['middleware' => [ 'api/v4', 'assert.privilege:' . UserEntity::AUTH_SUPERUSER ],

app/Services/Grapher.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
* http://www.gnu.org/licenses/gpl-2.0.html
2424
*/
2525

26-
use Illuminate\Cache\Repository as CacheRepository;
27-
2826
use IXP\Exceptions\Services\Grapher\{
2927
BadBackendException,
3028
ConfigurationException,
@@ -44,7 +42,7 @@
4442
Customer as CustomerGraph, // member agg over all physical ports
4543
VlanInterface as VlanIntGraph, // member VLAN interface
4644
P2p as P2pGraph,
47-
Smokeping as SmokepingGraph
45+
Latency as LatencyGraph
4846
};
4947

5048
use IXP\Contracts\Grapher\Backend as BackendContract;
@@ -304,12 +302,12 @@ public function p2p( VlanInterface $svli, VlanInterface $dvli ): P2pGraph {
304302

305303

306304
/**
307-
* Get an instance of a smoekping graph
305+
* Get an instance of a latency graph
308306
* @param VlanInterface $vli
309-
* @return \IXP\Services\Grapher\Graph\Smokeping
307+
* @return LatencyGraph
310308
*/
311-
public function smokeping( VlanInterface $vli ): SmokepingGraph {
312-
return new SmokepingGraph( $this, $vli );
309+
public function latency( VlanInterface $vli ): LatencyGraph {
310+
return new LatencyGraph( $this, $vli );
313311
}
314312

315313

@@ -346,9 +344,10 @@ public function cacheLifetime(): int {
346344

347345
/**
348346
* Get the cache repository
349-
* @return \Illuminate\Cache\Repository
347+
* @return \Illuminate\Contracts\Cache\Repository
350348
*/
351-
public function cacheRepository(): CacheRepository {
349+
public function cacheRepository(): \Illuminate\Contracts\Cache\Repository
350+
{
352351
return Cache::store( config('grapher.cache.store' ) );
353352
}
354353

app/Services/Grapher/Backend/Dummy.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ public function isMultiFileConfigurationSupported(): bool {
8787
*
8888
* {inheritDoc}
8989
*
90-
* @param \Entities\IXP $ixp The IXP to generate the config for (multi-IXP mode)
9190
* @param int $type The type of configuration to generate
9291
* @return array
9392
*/
94-
public function generateConfiguration( IXP $ixp, int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array
93+
public function generateConfiguration( int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array
9594
{
9695
return [];
9796
}
@@ -160,16 +159,16 @@ public static function supports(): array {
160159
'periods' => Graph::PERIODS,
161160
'types' => Graph::TYPES
162161
],
163-
'p2p' => [
162+
'latency' => [
164163
'protocols' => Graph::PROTOCOLS,
165164
'categories' => Graph::CATEGORIES,
166165
'periods' => Graph::PERIODS,
167166
'types' => Graph::TYPES
168167
],
169-
'smokeping' => [
168+
'p2p' => [
170169
'protocols' => Graph::PROTOCOLS,
171170
'categories' => Graph::CATEGORIES,
172-
'periods' => Graph\Smokeping::PERIODS,
171+
'periods' => Graph::PERIODS,
173172
'types' => Graph::TYPES
174173
],
175174
];

app/Services/Grapher/Backend/Mrtg.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
Rrd as RrdUtil
4242
};
4343

44-
use View,Log;
44+
use D2EM, View,Log;
4545

4646
/**
4747
* Grapher Backend -> Mrtg
@@ -100,16 +100,15 @@ public function isMultiFileConfigurationSupported(): bool {
100100
*
101101
* {inheritDoc}
102102
*
103-
* @param IXPEntity $ixp The IXP to generate the config for (multi-IXP mode)
104103
* @param int $type The type of configuration to generate
105104
* @return array
106105
*/
107-
public function generateConfiguration( IXPEntity $ixp, int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array
106+
public function generateConfiguration( int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array
108107
{
109108
return [
110109
View::make( 'services.grapher.mrtg.monolithic', [
111-
'ixp' => $ixp,
112-
'data' => $this->getPeeringPorts( $ixp ),
110+
'ixp' => D2EM::getRepository( IXPEntity::class )->getDefault(),
111+
'data' => $this->getPeeringPorts( D2EM::getRepository( IXPEntity::class )->getDefault() ),
113112
'snmppasswd' => config('grapher.backends.mrtg.snmppasswd'),
114113
]
115114
)->render(),

app/Services/Grapher/Backend/Sflow.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,10 @@ public function isMultiFileConfigurationSupported(): bool {
9292
*
9393
* {inheritDoc}
9494
*
95-
* @param IXP $ixp The IXP to generate the config for (multi-IXP mode)
9695
* @param int $config_type The type of configuration to generate
9796
* @return array
9897
*/
99-
public function generateConfiguration( IXP $ixp, int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array
98+
public function generateConfiguration( int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array
10099
{
101100
return [];
102101
}

0 commit comments

Comments
 (0)