is it possible to get the use of RAM using vues or php?

0
Hello, I would like to know if it is possible for me to do a system in vuejs or directly in php that will take up how much RAM I am using in total with all programs.

    
asked by anonymous 10.05.2018 / 22:03

1 answer

0

With PHP on Linux you can use /proc/meminfo and return the information in memory as an array:

<?php
function getSystemMemInfo(){       
    $data = explode("\n", file_get_contents("/proc/meminfo"));
    $meminfo = array();
    foreach($data as $line){
        list($key, $val) = explode(":", $line);
        $meminfo[$key] = trim($val);
    }
    return $meminfo;
}

foreach(getSystemMemInfo() as $key => $valor){
   echo "$key: $valor<br>";
}
?>

Result:

MemTotal: 24649124 kB     ← memória total
MemFree: 5182752 kB       ← memória livre
MemAvailable: 21418580 kB ← memória disponível
Buffers: 174160 kB
Cached: 13345472 kB
SwapCached: 6268 kB
Active: 10346544 kB
Inactive: 5484472 kB
Active(anon): 1571956 kB
Inactive(anon): 744208 kB
Active(file): 8774588 kB
Inactive(file): 4740264 kB
Unevictable: 23748 kB
Mlocked: 23748 kB
SwapTotal: 12287996 kB
SwapFree: 11448996 kB
Dirty: 1032 kB
Writeback: 0 kB
AnonPages: 2330460 kB
Mapped: 132848 kB
Shmem: 472 kB
Slab: 3236908 kB
SReclaimable: 2795388 kB
SUnreclaim: 441520 kB
KernelStack: 21904 kB
PageTables: 59016 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 24612556 kB
Committed_AS: 16119768 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 369736 kB
VmallocChunk: 34346323084 kB
HardwareCorrupted: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 13996 kB
DirectMap2M: 3096576 kB
DirectMap1G: 22020096 kB

Source: SOen

    
10.05.2018 / 22:27