laravel-monitoring maintained by helori
Laravel Monitoring
Server monitoring for Laravel apps. No UI: the readings are exposed through a token-protected JSON API, to be read by any dashboard or monitoring service.
monitoring:record, every minute: CPU (load, real use, disk wait), RAM, disk, and optionally the RAM and connections of a local Postgres server.monitoring:sizes, every hour: size of chosen folders (storage/by default) and databases. Kept apart because measuring a big folder can take minutes.- Readings older than 35 days are deleted.
- A token-protected JSON API: last reading, bucketed series, sizes.
Linux and macOS. The readings are stored in Postgres, MySQL/MariaDB or SQLite, and the size of a database is measured on all three. The RAM and connections of the database server are measured for Postgres only.
Installation
composer require helori/laravel-monitoring
php artisan migrate
php artisan monitoring:token # prints MONITORING_TOKEN=…, add it to .env
The commands are added to the scheduler automatically (in the background, without overlapping): the app's schedule:run cron must be running. To schedule them yourself, set MONITORING_SCHEDULE=false.
To customize what is measured:
php artisan vendor:publish --tag=monitoring-config
| Key | Default | |
|---|---|---|
connection |
default connection | Where the readings are stored |
keep_days |
35 | Retention |
disk |
storage_path() |
A path on the disk to measure |
folders |
['storage' => storage_path()] |
Folders measured every hour, by label |
databases |
default connection | Connections whose database size is measured every hour |
postgres |
null |
Connection of a Postgres server on this machine (RAM, connections) |
api.token |
MONITORING_TOKEN |
Without a token the API answers 404 |
api.prefix |
api/monitoring |
|
api.max_points |
500 | The interval of a series grows to stay under it |
API
Every request carries Authorization: Bearer <MONITORING_TOKEN>. Dates are ISO 8601, in the app's timezone.
GET /api/monitoring/latest
The app, its server, the last reading and the last sizes. stale is true when the last reading is more than 3 minutes old: the scheduler is not running.
{
"app": {"name": "My App", "env": "production", "url": "https://example.com", "timezone": "Europe/Paris"},
"system": {"hostname": "web-1", "os": "Linux 6.8.0", "php": "8.3.29", "laravel": "13.2.0"},
"stale": false,
"reading": {"t": "2026-12-02T10:41:00+01:00", "cpu_cores": 8, "cpu_ratio": 30.5, "cpu_usage_ratio": 41.4, "disk_wait_ratio": 0.8, "ram_total": 17179869184, "ram_used": 11459977216, "ram_ratio": 66.7, "…": "…"},
"sizes": {"t": "2026-12-02T10:00:00+01:00", "folders": {"storage": 1234}, "databases": {"pgsql": 5409107291}}
}
GET /api/monitoring/series
Readings averaged by interval, with the maximum of each interval (<metric>_max, to see spikes).
| Parameter | Default |
|---|---|
from, to |
the last 24 hours |
metrics |
cpu_ratio,cpu_usage_ratio,ram_ratio,disk_ratio |
interval |
seconds, raised to the nearest of 60, 300, 900, 1800, 3600, 10800, 21600, 43200, 86400 that keeps the series under max_points |
Metrics: cpu_load, cpu_ratio, cpu_usage_ratio, disk_wait_ratio, ram_used, ram_ratio, disk_used, disk_ratio, postgres_ram_used, postgres_ram_ratio, postgres_connections.
{"from": "…", "to": "…", "interval": 300, "metrics": ["cpu_ratio"], "points": [{"t": "2026-12-02T10:00:00+01:00", "cpu_ratio": 16.7, "cpu_ratio_max": 30}]}
GET /api/monitoring/sizes
Sizes of the folders and databases over a period (default: the last 30 days), the last reading of each interval.
What the measures mean
cpu_ratio: load average over 1 minute / logical cores. 100 % = every core busy. On Linux it also counts the processes waiting for the disk.cpu_usage_ratio: real use of the CPU, sampled over 1 second.disk_wait_ratio(Linux only): share of the CPU time spent waiting for the disk. A highcpu_ratiowith a lowcpu_usage_ratioand a highdisk_wait_ratiomeans the disk, not the CPU, is the bottleneck.ram_used: total minus what is available for new allocations (reclaimable cache included).postgres_ram_used: sum of the RSS of the postgres processes, minusshared_bufferscounted once per process, plusshared_buffersonce. Each process only maps the part ofshared_buffersit touched, so this underestimates: it often equalsshared_buffersalone. Read it as a lower bound.
Tests
composer install
composer test # SQLite in memory
# On a real server: an empty database, dropped and recreated by the tests
TEST_DB_DRIVER=pgsql TEST_DB_DATABASE=packages_test TEST_DB_USERNAME=postgres composer test
TEST_DB_DRIVER=mysql TEST_DB_DATABASE=packages_test TEST_DB_USERNAME=root composer test
TEST_DB_HOST, TEST_DB_PORT and TEST_DB_PASSWORD are also read.