ramir1 / laravel-pulsar
Status endpoint for Pulsar monitoring (contract v0.1): the app writes check results, the package serves them as JSON.
Requires
- php: ^8.3
- laravel/framework: ^13.0
Requires (Dev)
- larastan/larastan: ^2.0 || ^3.0
- laravel/pint: ^1.0
- orchestra/testbench: ^11.0
- pestphp/pest: ^3.0 || ^4.0
- pestphp/pest-plugin-laravel: ^3.0 || ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Status endpoint for the Pulsar monitoring service (JSON contract v0.1).
Your application runs its own checks and writes the results into the Pulsar storage (Laravel cache);
the package serves them to Pulsar at GET /pulsar/v0.1/status.
Installation
composer require ramir1/laravel-pulsar
php artisan vendor:publish --tag=pulsar-config # optional
PULSAR_TOKEN=long-random-token
Use the same token in the service profile in Pulsar. If PULSAR_TOKEN is empty, the endpoint always returns 401.
Security notes:
- Serve the endpoint over HTTPS only: the token is sent in the
Authorizationheader and is readable over plain HTTP. - Use a long random token, e.g.
php -r "echo bin2hex(random_bytes(32));". - Requests are limited to 60 per minute per IP (
throttle:60,1) to slow down token guessing. Change the limit inroute.middleware; if you replace the array, keep a throttle in it.
Config (config/pulsar.php)
| Key | Default | Description |
|---|---|---|
enabled |
env('PULSAR_ENABLED', true) |
master switch, see below |
token |
env('PULSAR_TOKEN') |
Bearer token sent by Pulsar |
route.enabled |
true |
register the endpoint |
route.path |
env('PULSAR_PATH', 'pulsar/v0.1/status') |
endpoint path |
route.middleware |
['throttle:60,1'] |
extra middleware, run before the token check (which is always added) |
cache.store |
env('PULSAR_CACHE_STORE') |
cache store (null = default) |
cache.key |
pulsar:payload |
cache key |
cache.ttl |
null |
TTL in seconds, null = forever |
title |
env('PULSAR_TITLE', env('APP_NAME')) |
default meta.title |
With PULSAR_ENABLED=false the endpoint is not registered (404), writes through the facade are ignored
and payload() returns the "No data collected yet" stub. Block validation still runs, so invalid input
throws in every environment.
With several servers use a shared store (redis, database).
Writing data
use Ramir1\LaravelPulsar\Facades\Pulsar; use Ramir1\LaravelPulsar\Enums\State; Pulsar::state(State::Warning)->summary('Queue is growing')->preview(['orders', 'disk']); Pulsar::stat('orders', 128, 'Orders today', delta: '+14.2%', state: 'ok'); Pulsar::progress('disk', 92, label: 'Disk', unit: '%', state: State::Critical); Pulsar::status('services', [['name' => 'DB', 'state' => 'ok']], 'Services'); Pulsar::kv('env', ['PHP' => PHP_VERSION], 'Environment'); Pulsar::sparkline('rps', [12, 15, 11], current: '11 rps'); Pulsar::push('rps', 21, current: '21 rps'); // append a point, last 200 kept Pulsar::put(['id' => 'map', 'view' => 'map']); // raw block Pulsar::forget('rps'); Pulsar::flush(); Pulsar::payload(); // the JSON served by the endpoint
Blocks are upserted by id. Block classes validate input and throw InvalidArgumentException
where Pulsar would otherwise render a fallback block; more than 100 blocks throws OverflowException.
meta.state is set manually only (default ok). Until anything is written the endpoint returns
state: "warning" with summary: "No data collected yet".
Development
docker compose run --rm php composer install
docker compose run --rm php composer test
docker compose run --rm php composer pint
docker compose run --rm php composer phpstan