1. Go to this page and download the library: Download choval/sys-stats library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
choval / sys-stats example snippets
$stats = new \Choval\System\Stats;
/*
Creates the stats object
*/
$stats->getMemUsage();
/*
Memory usage of current PHP execution.
All results in Bytes as PHP memory_get_usage & memory_get_peak_usage.
Array
(
[peak] => inactive+active peak
[peak_active] => active peak
[current] => inactive+active currently
[current_active] => active currently
)
*/
$stats->getMemStats();
/*
Memory stats.
All results in MiB, not MB.
Array
(
[total] => system memory
[free] => free memory (keep in mind linux memory usage, this will usually be close to 1-2)
[used] => memory under use by applications and system
[available] => available memory for use
[capacity] => PERCENTAGE (without '%') of available memory/total memory
)
*/
$stats->getCpuModels();
/*
Gets the CPU model, repeated by number of (logical) CPUs (ncpu)
Array
(
[0] => Intel(R) Core(TM) M-5Y31 CPU
[1] => Intel(R) Core(TM) M-5Y31 CPU
[2] => Intel(R) Core(TM) M-5Y31 CPU
[3] => Intel(R) Core(TM) M-5Y31 CPU
)
*/
$stats->getCpuLoads();
/*
Gets the CPU load, all results in PERCENTAGE (without '%').
Unlike PHP's results, these are percentage of the system capacity already.
Keep in mind some systems may underclock depending on load.
Array
(
[1_min] => PERCENTAGE of load/capacity last min
[5_min] => PERCENTAGE of load/capacity last 5min
[15_min] => PERCENTAGE of load/capacity last 15min
)
*/
$stats->getDiskStats();
/*
Disk stats.
All results in MiB, not MB. NOT BYTES!
Only return mounted disks.
Array
(
[0] => Array
(
[filesystem] => The device, ie: /dev/sda1
[size] => Capacity in MiB
[used] => Used number of MiB
[available] => Available capacity
[capacity] => PERCENTAGE (without '%') of available/size
[mounted_on] => Mount path
)
)
*/
$stats->getSingleDiskStats( getcwd() );
/*
This returns the same data for the disk/partition the current working dir is using.
Or point to a different directory and get the stats.
Array
(
[filesystem] => The device, ie: /dev/sda1
[size] => Capacity in MiB
[used] => Used number of MiB
[available] => Available capacity
[capacity] => PERCENTAGE (without '%') of available/size
[mounted_on] => Mount path
)
*/
$stats->getNetStats();
/*
Returns network stats for every network interface.
Array
(
[0] => Array
(
[interface] => Interface name
[mtu] => MTU, int
[addresses] => Array
(
[mac] => Mac address
[ipv4] => IPv4
[ipv6] => IPv6
)
[packets_in] => Packets, float
[packets_out] => Packets, float
[bytes_in] => Bytes, float
[bytes_out] => Bytes, float
[errors_in] => Errors, float
[errors_out] => Errors, float
)
)
*/
$stats->output();
/*
Returns all the data in one single call.
Array
(
[cpu_loads] => getCpuLoads()
[cpu_models] => getCpuModels()
[disk_stats] => getDiskStats()
[mem_stats] => getMemStats()
[mem_usage] => getMemUsage()
[net_stats] => getNetStats()
[updated] => Time of stats
)
*/
$stats = new \Choval\System\Stats($loop);
/*
Creates the stats object, without frequency.
All methods will return a React\Promise\Promise.
*/
$stats = new \Choval\System\Stats($loop, 60);
/*
Runs the stats every 60 secs in the background.
All methods will return a React\Promise\Promise as well,
but the data will be retrieved from the cache of the
last background execution.
*/
$stats->refresh();
/*
Forces a refresh of all data ignoring the frequency.
Will not reset the frequency timer.
Returns a promise.
*/
$stats->getUpdated();
/*
Returns the time of the stats.
Does not return a promise!
*/
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.