Is it possible to take the use of RAM memory using vuejs or in php?

Asked

Viewed 86 times

0

Hello, I wonder if it is possible to make a system in vuejs or directly in php that takes how many of RAM memory I am using in total, with all programs.

1 answer

0

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

<?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>";
}
?>

Upshot:

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

  • This is only for Linux ?

  • Yes. Vc uses windows?

  • The system I am developing will be for both platform, so I would need for windows and linux

  • something that every 5 seconds updated

  • The problem is that I don’t have a way to test on Windows, but see if this answer works: https://stackoverflow.com/a/12475735/1377664

  • I managed to do, thanks for the help.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.