lumen support
This commit is contained in:
parent
6e874128e8
commit
31eaa993eb
5 changed files with 65 additions and 7 deletions
26
src/LaravelPrometheusServiceProvider.php
Normal file
26
src/LaravelPrometheusServiceProvider.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Superbalist\LaravelPrometheusExporter;
|
||||||
|
|
||||||
|
class LaravelPrometheusServiceProvider extends PrometheusServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Perform post-registration booting of services.
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
$this->publishes([
|
||||||
|
__DIR__ . '/../config/prometheus.php' => config_path('prometheus.php'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
parent::boot();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load routes.
|
||||||
|
*/
|
||||||
|
protected function loadRoutes()
|
||||||
|
{
|
||||||
|
$this->loadRoutesFrom(__DIR__ . '/laravel_routes.php');
|
||||||
|
}
|
||||||
|
}
|
17
src/LumenPrometheusServiceProvider.php
Normal file
17
src/LumenPrometheusServiceProvider.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Superbalist\LaravelPrometheusExporter;
|
||||||
|
|
||||||
|
class LumenPrometheusServiceProvider extends PrometheusServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Load routes.
|
||||||
|
*/
|
||||||
|
protected function loadRoutes()
|
||||||
|
{
|
||||||
|
$this->app->router
|
||||||
|
->group(['namespace' => 'Superbalist\LaravelPrometheusExporter'], function ($router) {
|
||||||
|
require __DIR__ . '/lumen_routes.php';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,19 +7,17 @@ use Illuminate\Support\ServiceProvider;
|
||||||
use Prometheus\CollectorRegistry;
|
use Prometheus\CollectorRegistry;
|
||||||
use Prometheus\Storage\Adapter;
|
use Prometheus\Storage\Adapter;
|
||||||
|
|
||||||
class PrometheusServiceProvider extends ServiceProvider
|
abstract class PrometheusServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Perform post-registration booting of services.
|
* Perform post-registration booting of services.
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$this->publishes([
|
$this->mergeConfigFrom(__DIR__ . '/../config/prometheus.php', 'prometheus');
|
||||||
__DIR__ . '/../config/prometheus.php' => config_path('prometheus.php'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (config('prometheus.metrics_route_enabled')) {
|
if (config('prometheus.metrics_route_enabled')) {
|
||||||
$this->loadRoutesFrom(__DIR__ . '/routes.php');
|
$this->loadRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
$exporter = $this->app->make(PrometheusExporter::class); /* @var PrometheusExporter $exporter */
|
$exporter = $this->app->make(PrometheusExporter::class); /* @var PrometheusExporter $exporter */
|
||||||
|
@ -29,13 +27,16 @@ class PrometheusServiceProvider extends ServiceProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load routes.
|
||||||
|
*/
|
||||||
|
abstract protected function loadRoutes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register bindings in the container.
|
* Register bindings in the container.
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->mergeConfigFrom(__DIR__ . '/../config/prometheus.php', 'prometheus');
|
|
||||||
|
|
||||||
$this->app->singleton(PrometheusExporter::class, function ($app) {
|
$this->app->singleton(PrometheusExporter::class, function ($app) {
|
||||||
$adapter = $app['prometheus.storage_adapter'];
|
$adapter = $app['prometheus.storage_adapter'];
|
||||||
$prometheus = new CollectorRegistry($adapter);
|
$prometheus = new CollectorRegistry($adapter);
|
||||||
|
|
7
src/laravel_routes.php
Normal file
7
src/laravel_routes.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
Route::get(config('prometheus.metrics_route_path'), [
|
||||||
|
'as' => config('prometheus.metrics_route_name'),
|
||||||
|
'middleware' => config('prometheus.metrics_route_middleware'),
|
||||||
|
'uses' => \Superbalist\LaravelPrometheusExporter\MetricsController::class . '@getMetrics',
|
||||||
|
]);
|
7
src/lumen_routes.php
Normal file
7
src/lumen_routes.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$router->get(config('prometheus.metrics_route_path'), [
|
||||||
|
'as' => config('prometheus.metrics_route_name'),
|
||||||
|
'middleware' => config('prometheus.metrics_route_middleware'),
|
||||||
|
'uses' => 'MetricsController@getMetrics'
|
||||||
|
]);
|
Loading…
Add table
Add a link
Reference in a new issue