Analysis of the machine / server using php

5

I am creating a system report, I honestly did not know that PHP did this, I searched and found it did, but I did not find a useful explanation, I just found PHP SYS INFO as a reference.

When I say machine I mean = server / pc / machine where the system is running

My points of doubt follow this listing ..

  • Address information - > Server IP, Hostname
  • System - > Last boot, active at what time, active and idle processes, CPU temperature and 'SYS'
  • Memory Usage - > How much of the total, how much is being used
  • If there is an article, or guidance to get it, thank you.

        
    asked by anonymous 26.12.2014 / 02:36

    2 answers

    7

    There is an interesting project in GitHub that allows us to get a "universe" of information about the system:

    phpSysInfo

    A great advantage is the support we get because the project is tested at numerous platforms :

      

    • Linux 2.6.x
      • FreeBSD 7.x
      • OpenBSD 2.8+
      • NetBSD
      • DragonFly
      • IBM AIX
      • HP-UX
      • Darwin / OSX
      • Win 2000 / Win 2003 / Win XP / Win Vista / Win 7 / Win 8 / Win 8.1
      • > PHP 5.2 or later ◦With PCRE, XML, XSL, MBString and SimpleXML extension.

    Installation

    The installation process is relatively simple but lacks two points of attention described below along with the installation notes:

  • Unpack the source code that can be downloaded here to the root of the server.

  • In the folder there is a configuration file called phpsysinfo.ini.new , if the installation that is being done is a new installation, you should copy this file to phpsysinfo.ini and edit it:

    cp phpsysinfo.ini.new phpsysinfo.ini
    
  • Perform the following checks on the php.ini server file:

    • Verify that include_path entry contains .
    • Since phpSysInfo requires access to many files in /proc among others, it is important to have safe_mode disabled:

      To do this in the file php.ini , change the line from safe_mode to:

      safe_mode = Off
      

    Finally, ensure that the PHP extension is installed with the name php-xml , being the same thing needed for a correct operation of phpSysInfo.

  • If changes have been made to the php.ini file, just reboot the server and you can start the fun.

    Note: To locate the php.ini file on the server, from the command line we can use the following command:

    find / -name php.ini -print
    

    Demonstration

    There is a multi-language online demonstration that demonstrates the innumerable potentialities of this project:

    link

    And much much more ...

    Data format

    Data can also be extracted through the API in the format that suits what we want to do:

    01.01.2015 / 00:01
    7

    Considering that your PHP server is Linux (you hardly have PHP installed on Windows), how to get the information you want:

    • IP: $_SERVER['SERVER_ADDR']

    • Host Name: $_SERVER['SERVER_NAME']

    • Most recent boot: shell_exec('uptime') or read /proc/uptime file containing 2 values. The 1st is Uptime in seconds

    • Active and inactive processes: shellexec('ps -eF') process output according to your needs.

    • Temperature

      $temp    = exec('lm_sensors | grep \'°\'');
      $tempr   = explode('+', $temp);
      $tempval = preg_replace("/[^0-9,.]/", "", $tempr[1]);
      
    • Memory being used: memory_get_usage(true) (for your PHP script)

    • Total memory being used on the server: parse the output of the command free (contrib. @GuilhermeNascimento)

    • Total memory: read the file /proc/meminfo

    Editing based on @GuilhermeNascimento's comment:

    "For lm-sensors to work, the server must have it installed and usually SHARED servers can not be installed on their own (perhaps the server may or may not have been installed)."

        
    26.12.2014 / 14:01