Page 1 of 1

PHP Server info Script

Posted: Sat Nov 26, 2011 7:24 am
by dmallia
So i want to do a basic admin page for my servers to display information.
The information that has to display is this:
Operating System Name
IP address
Uptime
CPU Information and CPU Load
Total Memory and memory being used
Total HDD Space and HDD Used Space

They both have linux OS(don't know if it makes any difference from windows)

Any idea on how to have that information?(till know i only know $_SERVER['SERVER_ADDR'] to get the ip adress)

Re: PHP Server info Script

Posted: Sat Nov 26, 2011 9:23 am
by Celauran
You will almost certainly need either exec() or system() which, on shared hosting, are unlikely to be enabled. I've listed the appropriate commands anyway.
  • Operating System Name: uname -o
  • Uptime: uptime
  • CPU Information and CPU Load: not sure
  • Total Memory and memory being used: free
  • Total HDD Space and HDD Used Space: df

Re: PHP Server info Script

Posted: Sat Nov 26, 2011 2:27 pm
by dmallia
To display the cpu usage load i found this ajax script http://www.obout.com/AJAXPage/ex_cpumon.aspx but i don't know how i can insert it in my php page. Anyone knows how i can add this script?

Re: PHP Server info Script

Posted: Sat Nov 26, 2011 2:54 pm
by Celauran
It appears to be written in C#, so I expect that will pose some problems.

Re: PHP Server info Script

Posted: Sat Nov 26, 2011 3:41 pm
by dmallia
hope i will fine another one that will work, as i don't know how to program in ajax

Re: PHP Server info Script

Posted: Sun Nov 27, 2011 6:37 am
by dmallia
So for the cpu information i did this script.

Code: Select all

<?php

	$cpuinfo = file("/proc/cpuinfo");

	for ($i = 0; $i < count($cpuinfo); $i++)
		{
			list($item, $data) = split(":", $cpuinfo[$i], 2);
			$item = chop($item);
			$data = chop($data);
			if ($item == "processor") {$total_cpu++; }
			if ($item == "vendor_id") { $vendor_id = $data; }
			if ($item == "model name") { $cpu_name = $data; }
			if ($item == "cpu MHz") {$cpu_speed = " " . floor($data);}
		}

	$cpu_info = $total_cpu.'x '.$vendor_id.' '.$cpu_name.' '.$cpu_speed." MHz\n";

	$cpu = "<p>CPU :".$cpu_info."</p>";

	echo $cpu;
?>
but i'm getting these errors with the cpu information. Anyone can tell me how i can remove these errors?

Code: Select all

Notice: Undefined variable: total_cpu in /var/www/html/daniel/index.php on line 10 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7 Notice: Undefined offset: 1 in /var/www/html/daniel/index.php on line 7

CPU :4x GenuineIntel Intel(R) Xeon(R) CPU X3360 @ 2.83GHz 2825 MHz

Re: PHP Server info Script

Posted: Mon Nov 28, 2011 2:30 pm
by dmallia
Problem solved. Just made another script and instead of a loop i made the loop my self.