Skip to content

Latest commit

 

History

History
175 lines (137 loc) · 6.36 KB

README.md

File metadata and controls

175 lines (137 loc) · 6.36 KB

Laravel Octane Prometheus Exporter

CI codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

Export Laravel Octane metrics using this Prometheus exporter.

🤝 Supporting

If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with Github Sponsors. 📦

🚀 Installation

You can install the package via composer:

composer require renoki-co/octane-exporter

In case you haven't published your Octane settings, do so:

php artisan octane:install

Next up, add the following Octane tables in your config/octane.php. These tables will be used to keep track of stats for the events:

return [

    'tables' => [
        'octane_exporter_requests:1' => [
            'total_count' => 'int',
            '2xx_count' => 'int',
            '3xx_count' => 'int',
            '4xx_count' => 'int',
            '5xx_count' => 'int',
        ],
        'octane_exporter_tasks:1' => [
            'total_count' => 'int',
            'active_count' => 'int',
        ],
        'octane_exporter_workers:1' => [
            'active_count' => 'int',
        ],
        'octane_exporter_ticks:1' => [
            'total_count' => 'int',
            'active_count' => 'int',
        ],

        // ...
    ],

];

The final step is to add the following listeners after the already existent ones in config/octane.php:

return [

    'listeners' => [
        WorkerStarting::class => [
            // ...
            \RenokiCo\OctaneExporter\Listeners\TrackStartedWorkers::class,
        ],

        RequestTerminated::class => [
            // ...
            \RenokiCo\OctaneExporter\Listeners\TrackTerminatedRequests::class,
        ],

        TaskReceived::class => [
            // ...
            \RenokiCo\OctaneExporter\Listeners\TrackReceivedTasks::class,
        ],

        TaskTerminated::class => [
            // ...
            \RenokiCo\OctaneExporter\Listeners\TrackTerminatedTasks::class,
        ],

        TickReceived::class => [
            // ...
            \RenokiCo\OctaneExporter\Listeners\TrackReceivedTicks::class,
        ],

        TickTerminated::class => [
            // ...
            \RenokiCo\OctaneExporter\Listeners\TrackTerminatedTicks::class,
        ],

        WorkerStopping::class => [
            // ...
            \RenokiCo\OctaneExporter\Listeners\TrackStoppedWorkers::class,
        ],
    ],

];

🙌 Usage

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.

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.

# HELP laravel_octane_active_tasks_count Get the number of active tasks that pass through Octane.
# TYPE laravel_octane_active_tasks_count gauge
laravel_octane_active_tasks_count{remote_addr="",addr="",name=""} 0
# HELP laravel_octane_active_ticks_count Get the number of active ticks that run currently in Octane.
# TYPE laravel_octane_active_ticks_count gauge
laravel_octane_active_ticks_count{remote_addr="",addr="",name=""} 0
# HELP laravel_octane_active_workers_count Get the number of active workers for Octane.
# TYPE laravel_octane_active_workers_count gauge
laravel_octane_active_workers_count{remote_addr="",addr="",name=""} 8
# HELP laravel_octane_requests_count Get the number of requests, by status, that passed through Octane.
# TYPE laravel_octane_requests_count gauge
laravel_octane_requests_count{remote_addr="",addr="",name="",status="2xx_count"} 7
laravel_octane_requests_count{remote_addr="",addr="",name="",status="3xx_count"} 0
laravel_octane_requests_count{remote_addr="",addr="",name="",status="4xx_count"} 0
laravel_octane_requests_count{remote_addr="",addr="",name="",status="5xx_count"} 0
laravel_octane_requests_count{remote_addr="",addr="",name="",status="total_count"} 7
# HELP laravel_octane_status Check if the octane service is running. 1 = active, 0 = inactive
# TYPE laravel_octane_status gauge
laravel_octane_status{remote_addr="",addr="",name=""} 1
# HELP laravel_octane_total_tasks_count Get the number of total tasks that passed through Octane.
# TYPE laravel_octane_total_tasks_count gauge
laravel_octane_total_tasks_count{remote_addr="",addr="",name=""} 0
# HELP laravel_octane_total_ticks_count Get the number of total ticks that got through Octane. This is the equivalent of seconds passed since this server is alive.
# TYPE laravel_octane_total_ticks_count gauge
laravel_octane_total_ticks_count{remote_addr="",addr="",name=""} 1242
# HELP php_info Information about the PHP environment.
# TYPE php_info gauge
php_info{version="8.0.11"} 1

🐛 Testing

vendor/bin/phpunit

🤝 Contributing

Please see CONTRIBUTING for details.

🔒 Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

🎉 Credits