diff --git a/src/LaravelPrometheusServiceProvider.php b/src/LaravelPrometheusServiceProvider.php new file mode 100644 index 0000000..9719662 --- /dev/null +++ b/src/LaravelPrometheusServiceProvider.php @@ -0,0 +1,26 @@ +publishes([ + __DIR__ . '/../config/prometheus.php' => config_path('prometheus.php'), + ]); + + parent::boot(); + } + + /** + * Load routes. + */ + protected function loadRoutes() + { + $this->loadRoutesFrom(__DIR__ . '/laravel_routes.php'); + } +} diff --git a/src/LumenPrometheusServiceProvider.php b/src/LumenPrometheusServiceProvider.php new file mode 100644 index 0000000..7ecfb3b --- /dev/null +++ b/src/LumenPrometheusServiceProvider.php @@ -0,0 +1,17 @@ +app->router + ->group(['namespace' => 'Superbalist\LaravelPrometheusExporter'], function ($router) { + require __DIR__ . '/lumen_routes.php'; + }); + } +} diff --git a/src/PrometheusServiceProvider.php b/src/PrometheusServiceProvider.php index 4b189f5..cf7bf95 100644 --- a/src/PrometheusServiceProvider.php +++ b/src/PrometheusServiceProvider.php @@ -7,19 +7,17 @@ use Illuminate\Support\ServiceProvider; use Prometheus\CollectorRegistry; use Prometheus\Storage\Adapter; -class PrometheusServiceProvider extends ServiceProvider +abstract class PrometheusServiceProvider extends ServiceProvider { /** * Perform post-registration booting of services. */ public function boot() { - $this->publishes([ - __DIR__ . '/../config/prometheus.php' => config_path('prometheus.php'), - ]); + $this->mergeConfigFrom(__DIR__ . '/../config/prometheus.php', 'prometheus'); if (config('prometheus.metrics_route_enabled')) { - $this->loadRoutesFrom(__DIR__ . '/routes.php'); + $this->loadRoutes(); } $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. */ public function register() { - $this->mergeConfigFrom(__DIR__ . '/../config/prometheus.php', 'prometheus'); - $this->app->singleton(PrometheusExporter::class, function ($app) { $adapter = $app['prometheus.storage_adapter']; $prometheus = new CollectorRegistry($adapter); diff --git a/src/laravel_routes.php b/src/laravel_routes.php new file mode 100644 index 0000000..e1f4669 --- /dev/null +++ b/src/laravel_routes.php @@ -0,0 +1,7 @@ + config('prometheus.metrics_route_name'), + 'middleware' => config('prometheus.metrics_route_middleware'), + 'uses' => \Superbalist\LaravelPrometheusExporter\MetricsController::class . '@getMetrics', +]); diff --git a/src/lumen_routes.php b/src/lumen_routes.php new file mode 100644 index 0000000..9889829 --- /dev/null +++ b/src/lumen_routes.php @@ -0,0 +1,7 @@ +get(config('prometheus.metrics_route_path'), [ + 'as' => config('prometheus.metrics_route_name'), + 'middleware' => config('prometheus.metrics_route_middleware'), + 'uses' => 'MetricsController@getMetrics' +]);