innmind / server-status
Library to access various components of the operating system
5.0.0
2025-05-08 13:18 UTC
Requires
- php: ~8.2
- innmind/immutable: ~5.14
- innmind/server-control: ~6.0
- innmind/time-continuum: ^4.1.1
- innmind/url: ~4.0
- innmind/validation: ^2.0
- psr/log: ~3.0
Requires (Dev)
- innmind/black-box: ~6.1
- innmind/coding-standard: ~2.0
- innmind/static-analysis: ~1.2.1
- dev-develop
- 5.0.0
- 4.1.1
- 4.1.0
- 4.0.0
- 3.0.0
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-master
- dev-cs
- dev-internals
- dev-private-constructors
- dev-remove-exceptions
- dev-closed-value-objects
- dev-replace-maybe-by-attempt
- dev-update-dependencies
- dev-reuse-workflows
- dev-blackbox
- dev-static-analysis
- dev-license-date-range
- dev-fix-deprecations
This package is auto-updated.
Last update: 2025-05-08 13:21:30 UTC
README
Give an easy access to the cpu, memory, disk usages and the list of processes running on the machine.
Note
only works for Mac OSX and Linux for now.
Installation
composer require innmind/server-status
Usage
use Innmind\Server\Status\{ ServerFactory, Server\Disk\Volume\MountPoint, Server\Process\Pid, EnvironmentPath, }; use Innmind\Server\Control\ServerFactory as Control; use Innmind\TimeContinuum\Clock; use Innmind\TimeWarp\Halt\Usleep; use Innmind\IO\IO; $server = ServerFactory::build( $clock = Clock::live(), Control::build( $clock, IO::fromAmbientAuthority(), Usleep::new(), ), EnvironmentPath::of(\getenv('PATH')), ); $cpu = $server->cpu()->unwrap(); $cpu->user(); // percentage of the cpu used by the user $cpu->system(); // percentage of the cpu used by the system $cpu->idle(); // percentage of the cpu not used $cpu->cores(); // number of cores available $memory = $server->memory()->unwrap(); $memory->total(); // total memory of the server $memory->active(); // memory that is used by processes $memory->free(); // memory that is not used $memory->swap(); // memory that is used and located on disk $memory->used(); // total - free $loadAverage = $server->loadAverage()->unwrap(); $loadAverage->lastMinute(); $loadAverage->lastFiveMinutes(); $loadAverage->lastFifteenMinutes(); $server->disk()->get(MountPoint::of('/'))->match( function($disk) { $disk->size(); // total size of the volume $disk->available(); $disk->used(); $disk->usage(); // percentage of space being used }, fn() => null, // the mount point doesn't exist ); $server->processes()->get(Pid::of(1))->match( function($process) { $process->user(); // root in this case $process->cpu(); // percentage $process->memory(); // percentage $process->start(); // point in time at which the process started $process->command(); }, fn() => null, // the process doesn't exist ); $server->tmp(); // path to temp directory
You can easily log all the informations gathered via a simple decorator:
use Innmind\Server\Status\Server\Logger; use Psr\Log\LoggerInterface; $server = Logger::of($server, /** instance of LoggerInterface */);