Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to read stats from a remote server

Posted on 2011-09-02
8
Medium Priority
?
377 Views
Last Modified: 2012-05-12
I have a "central" ubuntu server which should read the load stats of several remote ubuntu/debian servers automatically every minute or so. Can it be done in PHP? What would be the best way to accomplish this?

Thanks
Jay
0
Comment
Question by:jiiins2
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Accepted Solution

by:
boon86 earned 1400 total points
ID: 36476782
This shows uptime and load average for 1 server called monitor.php
please place this to other server:

http://myserver1.com/monitor.php
http://myserver2.com/monitor.php
http://myserver3.com/monitor.php
http://myserver4.com/monitor.php

<?php

$uptime = trim(exec("cat /proc/uptime")); 
/*D*/print_r($uptime);
echo "<br/>";
$uptime = explode(" ", $uptime);
$idletime=$uptime[1];
$uptime=$uptime[0];


$day=86400;
$days=floor($uptime/$day);
echo "Up: $days days<br/>";
$utdelta=$uptime-($days*$day);

$hour=3600;
$hours=floor($utdelta/$hour);
echo "$hours hours<br/>";
$utdelta-=$hours*$hour;

$minute=60;
$minutes=floor($utdelta/$minute);
echo "$minutes minutes<br/>";
$utdelta-=round($minutes*$minute,2);

echo "$utdelta seconds<br/>";

echo '<b>Load Average</b><br/>';
echo '<div id="load">';
echo round((1-($idletime/$uptime))*100,3);
echo "%";
echo '</div>';
?>

Open in new window

This file to place at your central server:

http://mycentralubuntuserver.com/status.php

<?php
include('simple_html_dom.php');
//server 1
$html = file_get_html('http://myserver1.com/monitor.php');
foreach($html->find('div[id=load]') as $key => $info)
{
echo 'Load: '.$info->plaintext."<br />\n";
}
//server 2
$html = file_get_html('http://myserver2.com/monitor.php');
foreach($html->find('div[id=load]') as $key => $info)
{
echo 'Load: '.$info->plaintext."<br />\n";
}
//server 3
$html = file_get_html('http://myserver3.com/monitor.php');
foreach($html->find('div[id=load]') as $key => $info)
{
echo 'Load: '.$info->plaintext."<br />\n";
}
//server 4
$html = file_get_html('http://myserver4.com/monitor.php');
foreach($html->find('div[id=load]') as $key => $info)
{
echo 'Load: '.$info->plaintext."<br />\n";
}

?>

Open in new window


i included: simple_html_dom.php
                 complete.zip

so that you can refer, i tested my code before i post it here.

hope that help


simple-html-dom.php
complete.zip
0
 
LVL 3

Expert Comment

by:dbauermann
ID: 36476842
You can try to install Zabbix (www.zabbix.com).

This software collect a lot of information about servers, not only load stats...
0
 

Author Comment

by:jiiins2
ID: 36476892
@boon86

Thanks, very interesting. The main stats I'd need to retrive are the current cpu load and mem usage. Would your script provide those as well?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:boon86
ID: 36477666
current output is like this:

2312931.92 2298002.62
Up: 26 days
18 hours
28 minutes
51.9199999999 seconds
Load Average
0.645%

Open in new window


for ram you might use:

echo system('free');

my code above its execute uptime command so you will get server load as well.
0
 

Author Comment

by:jiiins2
ID: 36479421
What about getting the current load instead of the average?
0
 
LVL 25

Expert Comment

by:madunix
ID: 36479442
I use Cacti , MRTG and Nagios, to monitor servers.

Mylist:
http://www.groundworkopensource.com GroundWork Monitor Enterprise
http://www.hyperic.com Hyperic HQ
http://www.icinga.org Icinga
http://www.nagios.com Nagios
http://www.n-able.com N-central
http://www.op5.com op5 Monitor
http://www.open-itcockpit.com openITCockpit
http://www.opennms.org OpenNMS
http://www.hp.com/de/bto HP OpenView
http://www.bmc.com BMC PATROL ProactiveNet Performance Management
http://www.shinken-monitoring.org Shinken
http://www.ibm.com/software/de/tivoli IBM Tivoli
http://www.ca.com/de CA Unicenter
http://www.whatsupgold.com WhatsUp Gold
http://www.zabbix.com Zabbix
http://www.zenoss.com Zenoss Enterprise
http://oss.oetiker.ch/mrtg/ mrtg
0
 

Author Comment

by:jiiins2
ID: 36479464
Anything fred and extremely easy to use?
0
 
LVL 25

Assisted Solution

by:madunix
madunix earned 600 total points
ID: 36479616
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month5 days, 19 hours left to enroll

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question