Solved

How to read stats from a remote server

Posted on 2011-09-02
8
350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Accepted Solution

by:
boon86 earned 350 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
Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

 
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 150 total points
ID: 36479616
0

Featured Post

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

739 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