PHP code example of iliaal / statgrab

1. Go to this page and download the library: Download iliaal/statgrab 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/ */

    

iliaal / statgrab example snippets


sg_cpu_percent_usage(int $source = Statgrab::CPU_PERCENT_ENTIRE): array|false
//   $source: CPU_PERCENT_ENTIRE (cumulative since boot, default),
//            CPU_PERCENT_LAST_DIFF (since previous internal snapshot),
//            CPU_PERCENT_NEW_DIFF (since this call)
sg_cpu_totals(): array|false              // cumulative jiffies + ctx switches/syscalls/IRQs
sg_cpu_diff(): array|false                // jiffies since last call
sg_diskio_stats(): array|false            // [diskname => [read, written, time_frame]]
sg_diskio_stats_diff(): array|false
sg_fs_stats(): array|false                // mounted filesystems with size/used/inodes/...
sg_general_stats(): array|false           // os_name, hostname, uptime, ncpus, ...
sg_load_stats(): array|false              // min1, min5, min15
sg_memory_stats(): array|false            // total, free, used, cache (bytes)
sg_swap_stats(): array|false              // total, free, used (bytes)
sg_network_stats(): array|false           // [ifname => sent/received/packets/...]
sg_network_stats_diff(): array|false
sg_page_stats(): array|false              // pages_in, pages_out (cumulative)
sg_page_stats_diff(): array|false
sg_process_count(): array|false           // total, running, sleeping, stopped, zombie
sg_process_stats(?int $sort_order = null, int $num_entries = 0): array|false  // $num_entries 0 or > count returns all entries; negative throws ValueError
sg_user_stats(): array|false              // [{login_name, device, pid, login_time, ...}]
sg_network_iface_stats(): array|false     // [ifname => {speed, duplex, active}]
// 2.1 additions:
sg_valid_filesystems(): array|false       // list of fs-type strings libstatgrab treats as "real"
sg_set_valid_filesystems(array $filesystems): bool  // subsequent sg_fs_stats() only returns these fs_type values
sg_snapshot(): bool                       // re-seed libstatgrab's internal counters (call before a sliding-window sample)
sg_error_details(): array|false           // [code, errno, message, arg] for the pending libstatgrab error, or false if none

$sg = new Statgrab();
$sg->cpu();                                // cpu(int $source = Statgrab::CPU_PERCENT_ENTIRE): array|false
$sg->host();
$sg->memory();
$sg->processes(Statgrab::SORT_CPU, 10);    // processes(?int $sort_order = null, int $num_entries = 0): array|false
$sg->disks(diff: true);
$sg->validFilesystems();                   // array|false — list of fs-type strings
$sg->setValidFilesystems(['ext4']);        // bool — subsequent filesystems() only returns these fs_type values
$sg->snapshot();                           // bool — re-seed libstatgrab's internal counters
$sg->errorDetails();                       // array|false — [code, errno, message, arg], or false if none pending