diff --git a/README.md b/README.md index eed7014..c7fc878 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,17 @@ return [ This package is pretty straightforward. Upon installing it, it will register the route at `/exporter/group/octane-metrics` and you can point Prometheus towards it for scraping. +```yaml +scrape_configs: + - job_name: 'octane' + metrics_path: '/exporter/group/octane-metrics' + scrape_interval: 5 + static_configs: + - targets: ['localhost:8000'] + labels: + app: 'my-octane-app' +``` + Please keep in mind that the metrics are calculated by-process. Point your Prometheus scraper to all instances that run the Octane start command. ``` diff --git a/src/Listeners/TrackTerminatedRequests.php b/src/Listeners/TrackTerminatedRequests.php index d6b9586..61f16b0 100644 --- a/src/Listeners/TrackTerminatedRequests.php +++ b/src/Listeners/TrackTerminatedRequests.php @@ -15,6 +15,11 @@ class TrackTerminatedRequests */ public function handle(RequestTerminated $event): void { + // Do not track requests for the metrics endpoints. + if ($event->request->routeIs('laravel-exporter.metrics')) { + return; + } + $this->incrementRequestsCount(); $statusCode = $event->response->getStatusCode(); diff --git a/tests/MetricsTest.php b/tests/MetricsTest.php index 732e84b..feca6d6 100644 --- a/tests/MetricsTest.php +++ b/tests/MetricsTest.php @@ -52,6 +52,7 @@ public function test_octane_requests() Request::create('/test2', 'GET'), Request::create('/test3', 'GET'), Request::create('/exporter/group/octane-metrics', 'GET'), + Request::create('/exporter/group/octane-metrics', 'GET'), ]); $app->bind('test-binding', function ($app) { @@ -126,6 +127,11 @@ public function test_octane_requests() 'status="4xx_count"} 1', $client->responses[3]->original ); + + $this->assertStringContainsString( + 'status="total_count"} 3', + $client->responses[4]->original + ); } public function test_octane_workers()