Search by

helori / laravel-monitoring

Helori

Server monitoring for Laravel: scheduled readings of CPU, RAM, disk, folders and databases, exposed through a token-protected API

Package info

github.com/helori/laravel-monitoring

pkg:composer/helori/laravel-monitoring

Statistics

Installs: 98

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.6 2026-12-02 21:09 UTC

This package is auto-updated.

Last update: 2026-12-02 21:14:09 UTC


README

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.

After updating the package, run php artisan migrate: new versions may add columns.

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) and the number of readings it holds (readings, one per minute). An interval can be partial (the first one of the period, the current one, a pause of the scheduler): weight its averages by readings to sum or average over the period. A total per minute such as app_requests is Σ app_requests × readings.

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, app_cpu_time, app_cpu_ratio, app_requests, app_jobs, app_commands, app_response_time, app_memory_peak, app_db_cpu_ratio, app_slow_requests.

{"from": "…", "to": "…", "interval": 300, "metrics": ["cpu_ratio"], "points": [{"t": "2026-12-02T10:00:00+01:00", "readings": 5, "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.

GET /api/monitoring/overview

What a dashboard shows of the app, in one request: everything latest gives, plus series (same parameters as /series; by default cpu_ratio, cpu_usage_ratio, ram_ratio, disk_ratio, app_cpu_ratio, app_requests, app_response_time, app_db_cpu_ratio, app_slow_requests) and size_history (/sizes over the same period).

{"app": {"…": "…"}, "system": {"…": "…"}, "stale": false, "reading": {"…": "…"}, "sizes": {"…": "…"},
 "series": {"interval": 900, "metrics": ["…"], "points": ["…"]}, "size_history": {"interval": 3600, "points": ["…"]}}

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. On Linux, the average since the previous reading (from the counters of /proc/stat, kept in the cache): the whole minute, not the second the reading is taken, when the schedulers of several apps start together. Elsewhere, and for the first reading, sampled over 1 second.
  • disk_wait_ratio (Linux only): share of the CPU time spent waiting for the disk. A high cpu_ratio with a low cpu_usage_ratio and a high disk_wait_ratio means the disk, not the CPU, is the bottleneck.
  • ram_used: total minus what is available for new allocations (reclaimable cache included).
  • app_*: what the app itself used since the previous reading, as opposed to the whole server that several apps may share. Each HTTP request, queued job and artisan command measures its CPU time (getrusage) and its memory peak; they are added up per minute in the cache and saved with the next reading.
    • app_cpu_time: CPU seconds; app_cpu_ratio: the same as a share of what the cores offered meanwhile, comparable with cpu_usage_ratio.
    • app_requests, app_jobs, app_commands: how many; app_response_time: average duration of the requests, in ms, from the start of the framework to the end of the request (the database's answers included).
    • app_slow_requests: requests that took MONITORING_SLOW_MS (1000 ms) or more: the few slow pages an average hides. A request killed before its end (PHP or web server timeout) is not counted at all: limit the duration of the queries rather than the request's.
    • app_db_cpu_ratio (Linux, Postgres): the share of the server used by the processes of the app's own database since the previous reading, comparable with app_cpu_ratio: the CPU of its queries, which the PHP measure cannot see. Read from the processes snapshot, at no cost for the requests. The database of the default connection, or of MONITORING_USAGE_DB_CONNECTION. Null with MySQL / MariaDB (one process for every database) or without the processes.
    • app_memory_peak: the highest memory peak of a single request, job or command, in bytes. It is not the RAM the app occupies: worker processes come and go.
    • Apart from app_db_cpu_ratio, only what runs in PHP is counted: the database server, the web server and the programs the app launches are not. Long-running commands (queue:work…) are not measured as a whole, their jobs are (usage.ignore_commands).
    • The cache store must be shared by the web and console processes: not array. Disable with MONITORING_USAGE=false.
  • processes (Linux only): the programs that used the CPU of the server since the previous reading, grouped and sorted, [{"label": "postgres mydb", "cpu_ratio": 38.3, "count": 4}, …]. cpu_ratio is a share of the whole server, comparable with cpu_usage_ratio. Labels: postgres <database> (a parallel worker counts for the query it helps), php-fpm <pool>, artisan <command> (<site folder>), otherwise the program (mysqld, nginx, ffmpeg…). This is what the app's own measure (app_*) cannot see: the database server, the programs the apps launch, the other sites of the server. Disable with MONITORING_PROCESSES=false.
  • long_queries: the queries running for more than a minute on the database server, by database, [{"database": "mydb", "count": 7, "longest": 5940}] (seconds). A query whose page gave up keeps running on the server and takes the CPU: such queries pile up when a slow page keeps being visited. Every database the connection's user can see (Postgres, MySQL / MariaDB), through the default connection or MONITORING_LONG_QUERIES_CONNECTION.
  • postgres_ram_used: sum of the RSS of the postgres processes, minus shared_buffers counted once per process, plus shared_buffers once. Each process only maps the part of shared_buffers it touched, so this underestimates: it often equals shared_buffers alone. 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.