• 0

Monitoring 'uptime' of more than one Server in PHP


Question

Hey Guys,

So I know how to display the 'uptime' command for one server, that's easy as pie. But what if I wanted to display uptime, load averages etc for more than one server, any way of integrating some kind of SSH into PHP or extracting the data some other way? (all servers running CentOS 5.5)

Thanks

Chris Pressland

10 answers to this question

Recommended Posts

  • 0

http://www.google.com/search?q=php+server+uptime+load

I think for checking multiple servers, you'd just need a HTML page that requests the php script from each server, and displays all of the results.

Eg...

-html page

--php_to_server1 (pulls uptime, load)

--php_to_server2 (pulls uptime, load)

  • 0

Okay, so I can pretty much get everything there fine, I'd:

<?php
$connection = ssh2_connect('192.168.20.222', 2200);

if (ssh2_auth_password($connection, 'root', 'examplepass'))
?>

But then what would I add to do a 'uptime' command? I can see commands for basically every other form of communication, but not this.

  • 0

Hey DaveLegg,

As you may have noticed in some of my previous threads the past few days on here, I'm a php n00b and I keep making trivial mistakes.

$connection = ssh2_connect('192.168.20.10', 2200);
if (ssh2_auth_password($connection, 'root', 'secret'))
$stream = ssh2_exec($connection, 'uptime');

Is what I have so far. Now, If I wanted this to connect to say 4 servers:

192.168.20.10

192.168.20.8

192.168.20.174

192.168.20.7

run uptime

then output as this

20.10 Stats: (output)

20.8 Stats: (output)

20.174 Stats: (output)

20.7 Stats: (output)

How'd I do it? lol... I suck. But I really am trying.

  • 0
  On 01/12/2010 at 19:19, Cupcakes said:

If you don't feel like coding everything for yourself and/or want something nice and fancy: http://www.status2k.com/ or http://serverpulsehq.com/.

Both are developed by the same individual.

None of my servers have Public IPs, and the data they serve is 100% Confidential, so everything is home grown i'm afraid.

  • 0

$servers = array(
    array('ip'=>'192.168.20.10','user'=>'root','pass'=>'secret'),
    array('ip'=>'192.168.20.8','user'=>'root','pass'=>'secret'),
    array('ip'=>'192.168.20.174','user'=>'root','pass'=>'secret'),
    array('ip'=>'192.168.20.7','user'=>'root','pass'=>'secret'))

foreach($servers as $server)
{
    $connection = ssh2_connect($server['ip'], 2200);
    if (ssh2_auth_password($connection, $server['user'], $server['pass']))
    {
        $server['uptime'] = stream_get_contents(ssh2_exec($connection, 'uptime'));
    }
}

You should then have the uptimes stored in the $servers array. NOTE: Haven't tested this at all, its just straight from the top of my head, so may require a bit of tweaking.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Chrome is now faster than ever and Google explains how it did it by Sayan Sen Back in June last year, Google touted some great performance improvements for Chrome and shared a blog post explaining in detail how it managed to achieve them. Today, almost exactly a year later, the search giant is back again with another such post as it continues to make performance gains in its Chromium browser. Interestingly, Google is not the only one to make such claims in recent times. Microsoft also highlighted recently how Edge was getting significantly faster. Both Microsoft and Google have cited the Speedometer 3.0 benchmark to test. We recently measured browsing performance during our T-Force DDR5-7200 RAM review, also using Speedometer 3.0. In its blog post, Google says that the development team made significant improvements to memory management and caching. This includes some redesigning effort of the memory layouts for many internal data structures used in components such as DOM, CSS, layout, and painting. Google says that Blink, the rendering engine in Chromium, now "avoids a lot of useless churn" so as to make better use of the CPU caches. In the areas where memory handling previously relied on garbage collection in Oilpan, like the DOM (document object model), the team has expanded that by shifting from using malloc (memory allocation function) to Oilpan entirely. For those wondering, Olipan is the garbage collector in Blink. Some of the memory management and caching improvements Google made are fundamental to good code optimization. If you recall, recently, a senior Microsoft engineer also pointed out many of these issues in apps that slow Windows down. There are also improvements in handling strings within the renderer; the hashing method was updated to rapidhash, which is said to improve performance. For when rendering tasks become inherently expensive, such as computing CSS styles for various elements, Google adds that caching techniques have been enhanced to achieve higher cache hits and fewer misses.
    • Laptop users, this appears to be single-sided so it should fit even in cases with thin slots.
    • Apple wouldn't be what it is today without China either...
    • I am struggling with the game, after playing it again after so many years.... feels so out of space.
  • Recent Achievements

    • Week One Done
      Uranus_enjoyer earned a badge
      Week One Done
    • Week One Done
      jfam earned a badge
      Week One Done
    • First Post
      survivor303 earned a badge
      First Post
    • Week One Done
      CHUNWEI earned a badge
      Week One Done
    • One Year In
      survivor303 earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      428
    2. 2
      +FloatingFatMan
      195
    3. 3
      snowy owl
      191
    4. 4
      ATLien_0
      184
    5. 5
      Xenon
      141
  • Tell a friend

    Love Neowin? Tell a friend!