
|
View Full Version : Access server uptime / loads etc
SH-Dave 04-14-2009, 08:11 AM Im a reseller so dont have full root access.
Can anyone advise how i would access the server uptime & information (ie loads, hdd space etc)
David
HostXV 04-14-2009, 10:27 AM Well, you can use HyperSpin to keep track of your UpTime. As for the Server Information, HDD Space, etc, those should be under your WHM 'Server Information'. If your provider does not allow you to view it, maybe request it from them. I have a script (I'll find it and give it to you) that shows every detail of a server, HDD Information, mounts, etc. I use this script all the time.
SH-Dave 04-14-2009, 01:13 PM The script would be perfect.
I have access to the info just looking to dispaly it outside cpanel
Thank you
HostXV 04-14-2009, 01:36 PM Hey,
Are you looking for something like this?
View: Click Here (http://hostelox.com/info.php)
That's what I use.
SH-Dave 04-14-2009, 01:44 PM yep that would be exactly something that i would be looking for
David
HostXV 04-14-2009, 02:02 PM Here you go. :)
<?
// Set the services you want the script to check.
// You can add more by just adding a line "servers name"=>"host/IP:port number",
// You can use game servers or anything.
// e.g. "IRCdaemon"=>"localhost:6667",
$services = array(
"http"=>"localhost:80",
"ssh"=>"localhost:22",
// "telnet"=>"localhost:23",
"ftp"=>"localhost:21",
// "smtp"=>"localhost:25",
"pop3"=>"localhost:110",
"mysql"=>"localhost:3306"
);
// Variables at the top of the page, date, uptime etc.
$date = date("l, M d, Y - h:i:s A");
$version = `uname -sr`;
$name = `hostname`;
$uptime = `uptime`;
// df command function, formatted into a table
function output_df()
{
$disk = `df`;
$lines = split("\n", $disk);
echo "<table border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">";
for ($i = 0; $i < sizeof($lines) && strlen($lines[$i]) > 1; $i++)
{
$cols = preg_split("/[\s]+/", $lines[$i]);
if ($i == 0)
echo "<tr bgcolor=\"black\"><font color=orange>";
else
echo "<tr>";
for ($j = 0; $j < 6; $j++)
{
if ($j == 0 || $j == 5)
$align = "left";
else if ($j == 1 || $j == 2 || $j == 3)
$align = "right";
else if ($j == 4)
$align = "center";
echo "<td align=$align> <font face=\"Verdana\" size=\"1\" color=\"orange\">$cols[$j]</font> </td>";
}
echo "</font></tr>";
}
echo "</table>";
}
// free comand function, formatted into a table
function output_free()
{
$free = `free`;
$lines = split("\n", $free);
echo "<table border=\"0\" align=\"center\" cellpadding=\"1\" cellspacing=\"1\">";
for ($i = 0; $i < sizeof($lines) && strlen($lines[$i]) > 1; $i++)
{
if ($i == 2) $i++;
$cols = preg_split("/[\s]+/", $lines[$i]);
if ($i == 0)
echo "<tr bgcolor=\"black\">";
else
echo "<tr>";
foreach ($cols as $data)
echo "<td align=right> <font face=\"Verdana\" size=\"1\" color=\"orange\">$data</font> </td>";
echo "</tr>";
}
echo "</table>";
}
// info grabbind done, onto the html
?>
<table border="0" align="center" cellpadding="1" cellspacing="0">
<tr><td>
<p><font face="Verdana" size="1"><b>System Status:</b> <? echo $name ?><br><b>Time:</b> <? echo $date ?></font></p>
<font face="Verdana" size="1">
<? echo $version ?><br>
<? echo $uptime ?>
<p><table>
<b>Services:</b><br>
<tr bgcolor="black"><td><font face="Verdana" size="1" color="orange">Status</font></td><td><font face="Verdana" size="1" color="orange">Service</font></td><td><font face="Verdana" size="1" color="orange">Host</font></td></tr>
<?
foreach ($services as $name=>$location)
{
list($host, $port) = split(":",$location);
$running = fsockopen($host, $port, $errno, $errstr, 30);
if (!$running)
$status_color = "red";
else
{
fclose($running);
$status_color = "green";
}
echo "<tr><td align=center><div align=\"center\" style=\"font-size: 13pt; color: $status_color\" width=\"15\" height=\"15\"><b>?</b></div></td><td><font face=\"Verdana\" size=\"1\">$name</font></td><td><font face=\"Verdana\" size=\"1\">$host</font></td></tr>";
}
?>
</table></p>
<b>Memory:</b><br>
<? output_free(); ?><br>
<b>Drive Info:</b><br>
<? output_df(); ?>
</font>
</td></tr></table>
SH-Dave 04-14-2009, 04:37 PM thanks for the script, however does not work with shell_exec disabled, grr
Annoying me now
David
HostXV 04-14-2009, 04:44 PM Oh, that's not good.
SH-Dave 04-14-2009, 04:49 PM is there anyway to disable it for just that domain?
David
HostXV 04-14-2009, 04:53 PM I'm not exactly sure. I hope someone else can assist you in this question.
sasha 04-14-2009, 05:16 PM If you can use cron to schedule jobs on server, you could make small script that will gather data for you and have it run every minute. Something like this:
#!/bin/sh
DATA_DIR=/home/username/html/data/
uname -sr > $DATA_DIR/version
hostname > $DATA_DIR/hostname
uptime > $DATA_DIR/uptime
free > $DATA_DIR/free
df > $DATA_DIR/df
... and then from your php rather then calling exec you read data from files with file_get_contents()
So instead
$version = `uname -sr`;
$name = `hostname`;
$uptime = `uptime`;
....
function output_df()
{
$disk = `df`;
...
function output_free()
{
$free = `free`;
...
You would have
$DATA_DIR = '/home/username/html/data/';
$version = file_get_contents("$DATA_DIR/version");
$name = file_get_contents("$DATA_DIR/hostname");
$uptime = file_get_contents("$DATA_DIR/uptime");
....
function output_df()
{
global $DATA_DIR;
$disk = file_get_contents("$DATA_DIR/df");
...
function output_free()
{
global $DATA_DIR;
$disk = file_get_contents("$DATA_DIR/free");
SH-Dave 04-14-2009, 06:20 PM ive tried using file_get_contents for the /proc/uptime scripts but getting open base dir restrictions.
Would the method of home/username/html/data work instead?
David
LH-Danny 04-14-2009, 06:54 PM There was a free script on sourceforge that did exactly this. I will have to take a look and find it for you.
LH-Danny 04-14-2009, 06:57 PM Nevermind, I've found it! :)
Link: http://phpsysinfo.sourceforge.net/
There is also some demo links on there, so you can see what it is like before you download. I'm not sure if it works with shell_exec disabled though.
SH-Dave 04-14-2009, 07:15 PM jus trying that
was hoping to write my own
David
SH-Dave 04-14-2009, 07:28 PM did not work :( the openbase_dir restriction
grrr
LH-Danny 04-14-2009, 07:32 PM In that case, I'm not sure that any script will work. The host puts the restrictions within php.ini, for security.
You could try asking if they would remove the restrictions... I doubt they would, but it's worth a try.
SH-Dave 04-14-2009, 07:42 PM Is there not a way to have it removed on a per domain basis so its not effecting all accounts>?
Dvaid
sasha 04-14-2009, 07:55 PM ive tried using file_get_contents for the /proc/uptime scripts but getting open base dir restrictions.
Would the method of home/username/html/data work instead?
David
If your php script is in /home/username/html/script.php and it works, chances are that IT can open any files in that folder and it's subfolders, so /home/username/html/data should work just fine.
LH-Danny 04-14-2009, 07:58 PM Is there not a way to have it removed on a per domain basis so its not effecting all accounts>?
Dvaid
Unless the server is using phpsuexec, then you won't be able to do this, as far as I know.
SH-Dave 04-14-2009, 08:23 PM cant find the folder with /data in it :(
Davdi
foobic 04-14-2009, 08:57 PM ive tried using file_get_contents for the /proc/uptime scripts but getting open base dir restrictions.
Would the method of home/username/html/data work instead?You'd need to set that path (home/username/html/data) to something in your system that exists and is allowed by open_basedir.
Alternatively you could just run the same commands on demand using a cgi program:
#!/bin/sh
echo "Content-type:text/plain"
echo
uname -sr
hostname
uptime
free
df
Call it test.cgi or test.sh, put it in your cgi-bin directory and chmod 0755.
SH-Dave 04-14-2009, 09:19 PM never played with cgi before, so no idea how i could get that info into a database, but i do find it ironic that it works fine in cgi
David
|