Solved

How to read stats from a remote server

Posted on 2011-09-02
8
345 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

749 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