Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Location
    UK
    Posts
    94

    Getting accurate memory used

    I have a script at http://dandd.cubepower.net/cubestatus-1p0p2/ (download at http://dandd.cubepower.net/cubestatus-1p0p2.zip )

    which does not display the mem used corretly, I am getting the free memory from /proc/meminfo, but it does not account for memory in cache. I am using the MemTotal: and MemFree: parts.

    Is there another way or could I use a different part of /proc/meminfo ?

    I know of the free command, but how do I use php to get the buffers and cached values?

  2. #2
    Join Date
    Jul 2003
    Location
    Kuwait
    Posts
    5,099
    Try this (could use some polishing):

    PHP Code:
    <?php

      $output 
    shell_exec('free');
      
    $lines explode("\n",$output);
      
    $mem_info explode("\t",$lines[1]);
      
    $mem_info preg_split("/[\\s]+/",$mem_info[0]);
      
    $swap explode("\t",$lines[3]);
      
    $swap preg_split("/[\\s]+/",$swap[0]);
      echo 
    "Memory Information\n";
      echo 
    "Total   : ".$mem_info[1]."\n";
      echo 
    "Used    : ".$mem_info[2]."\n";
      echo 
    "Free    : ".$mem_info[3]."\n";
      echo 
    "Shared  : ".$mem_info[4]."\n";
      echo 
    "Buffers : ".$mem_info[5]."\n";
      echo 
    "Cache   : ".$mem_info[6]."\n";
      echo 
    "Swap Information\n";
      echo 
    "Total   : ".$swap[1]."\n";
      echo 
    "Used    : ".$swap[2]."\n";
      echo 
    "Free    : ".$swap[3]."\n\n";

    ?>
    In order to understand recursion, one must first understand recursion.
    If you feel like it, you can read my blog
    Signal > Noise

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •