cboxdk/system-metrics
Get real-time system metrics from Linux and macOS in pure PHP. No extensions or dependencies—just type-safe, readonly classes covering CPU, memory, storage, network, load, uptime, and container metrics with explicit Result-based error handling.
ContainerLimits::$memoryWorkingSetBytes
reports cgroup memory usage minus inactive file cache, the way cAdvisor and
Kubernetes define the working set: memory.current - inactive_file on
cgroup v2, memory.usage_in_bytes - total_inactive_file on v1, floored at 0.
Raw usage counts reclaimable page cache, so a container that writes files
reads as close to its limit even though the kernel would hand that memory
back. memoryWorkingSetUtilizationPercentage() and
availableMemoryBytesFromWorkingSet() go with it. All three are null when
memory.stat cannot be read. memoryUsageBytes and its helpers are
unchanged, and so is limits().limits() in a cgroup without a memory limit pairs host total with host
usage. It used to pair the host's total with the usage of only the
processes inside the cgroup — every systemd service, and every container
whose limit sits on a parent cgroup (a Kubernetes pod or ECS task limit).
availableMemoryBytes() and memoryUtilization() described neither scope,
and a capacity planner built on them over-packed the machine. Cgroups with a
limit are unchanged. (#10)oomKillCount counts OOM kills. It read the under_oom flag,
which is 1 only while the cgroup is stalled with the OOM killer disabled, so
it stayed 0 however many processes the kernel killed. It now reads the
oom_kill counter in memory.oom_control (Linux 4.13+), and is null on
older kernels. cgroup v2 is unchanged. (#11)Thanks to @Orrison for #10 and #11.
SystemLimits::$cpuCores: Changed from int to float to support fractional CPU quotas (e.g. 200m = 0.2 cores, 1500m = 1.5 cores).SystemLimits::$currentCpuCores: Changed from int to float.SystemLimits::availableCpuCores(): Now returns float instead of int.SystemLimits::canScaleCpu(): Parameter changed from int to float.ContainerLimits::cpuUtilizationPercentage(): No longer capped at 100%. Can exceed 100% during over-quota burst scenarios.ContainerLimits::memoryUtilizationPercentage(): No longer capped at 100%.CompositeSystemLimitsSource was using availableCpuCores() (quota − usage) to populate the cpuCores limit field. Now uses cpuQuota directly. Same fix for memory.CompositeContainerMetricsSource created a new LinuxCgroupMetricsSource on every read(), resetting the parser's delta cache. cpuUsageCores was always null. The source is now persisted.(int) ceil() casts that rounded cgroup quotas to whole cores.// Before (v2.x)
$cores = $limits->cpuCores; // int: 1, 2, 4, 8
// After (v3.0)
$cores = $limits->cpuCores; // float: 0.2, 1.5, 4.0, 8.0
Closes #6
Full Changelog: https://github.com/cboxdk/system-metrics/compare/v2.3.1...v3.0.0
/.dockerenv, /run/.containerenv), PID 1 environment (container= for LXC/nspawn), and cgroup keywords (kubepods, docker, containerd, crio, lxc). No more false positives on VMs with systemd and cgroup v2.PRETTY_NAME as primary OS name. Fall back through VERSION_ID → VERSION → BUILD_ID for version. Use kernel release as final fallback instead of "unknown".Full Changelog: https://github.com/cboxdk/system-metrics/compare/v2.3.0...v2.3.1
/ means VM/bare metal, non-root scope means container.container field when environment detection confirms insideContainer is true./proc/1/environ check for systemd container markers (LXC/nspawn). Added cgroup v2 path heuristic for container scope detection.SystemLimits::isContainerized(): Deprecated. Use SystemMetrics::environment()->containerization->insideContainer for accurate container detection.Full Changelog: https://github.com/cboxdk/system-metrics/compare/v2.2.0...v2.3.0
Testing support with fake sources for all metric types. See CHANGELOG.md for details.
ProcessRunner::commandExists to eliminate redundant shell execution checks (~1-5ms savings per call)explode in LinuxProcStatParser and LinuxProcPidStatParser for reduced CPU overhead.md extension for correct navigation on Cbox.dk and GitHubFull Changelog: https://github.com/cboxdk/system-metrics/compare/v2.0.0...v2.0.1
PHPeek\SystemMetrics → Cbox\SystemMetricsgophpeek/system-metrics → cboxdk/system-metricsUpdate your composer.json:
composer remove gophpeek/system-metrics
composer require cboxdk/system-metrics
Update your imports:
// Before
use PHPeek\SystemMetrics\SystemMetrics;
// After
use Cbox\SystemMetrics\SystemMetrics;
Full Changelog: https://github.com/cboxdk/system-metrics/compare/v1.6.0...v2.0.0
How can I help you explore Laravel packages today?