Get real time system & server load notification on any IM using PHP and XMPP

Get real time system & server load notification on any IM using PHP and XMPP

There are various system and server related information which server administrators always need to have as soon as possible, infact I must say in real time. There are several open and closed source softwares in the market which can generate almost real time notifications for you. Most famous one being Nagios. In this blog post I will discuss, how to generate real time system notifications using PHP and XMPP. Specifically, I will present sample script using Jaxl (Jabber XMPP Client Library) for generating real time system load notifications, which can be received using any Instant Messengers.

We will be using system /proc/loadavg file to get real time system load information. If you are unaware about this file, here is in brief how this file is helpful to us:

sabhinav:~# cat /proc/loadavg
0.22 0.12 0.09 1/68 12621

where first three columns measure the CPU and IO utilization of last one, five and 10 minute periods. The fourth column shows the number of currently running processes and the total number of processes. The last column displays the last process ID used.

We will be using Jaxl PHP client library for handling the XMPP part. jaxl4serveradmins.class.php is an extension to Jaxl, providing various server administration helper function. Below is the code for server administration extension:


  define('JAXL_SERVER_ADMIN', '[email protected]');

  class JAXL extends XMPP {

    function eventMessage($fromJid, $content, $offline = FALSE) {

    function eventPresence($fromJid, $status, $photo) {

    function eventNewEMail($total,$thread,$url,$participation,$messages,$date,$senders,$labels,$subject,$snippet) {
      // Not used here. See jaxl4gmail.class.php for it's use case

    function setStatus() {
      // Set a custom status or use $this->status
      print "Setting Status...n";
      print "Donen";

      $this->addJob(JAXL_SERVER_LOAD_POLL_INTERVAL, array($this, 'parseServerLoad'));

    function parseServerLoad() {
      $loadavg = file_get_contents('/proc/loadavg');
      $this->sendMessage(JAXL_SERVER_ADMIN, $loadavg);


I have utilized addJob() method provided by Jaxl library, using which you can specify a callback to be called after every N seconds (in short a periodic cron). Here we add a periodic job to be runned every JAXL_SERVER_LOAD_POLL_INTERVAL seconds. parseServerLoad() method is called as the callback function.

$this->addJob(JAXL_SERVER_LOAD_POLL_INTERVAL, array($this, 'parseServerLoad'));

To keep the demo simple, I am simply sending the content of /proc/loadavg file as a message to server admins.

    function parseServerLoad() {
      $loadavg = file_get_contents('/proc/loadavg');
      $this->sendMessage(JAXL_SERVER_ADMIN, $loadavg);

Running it for your servers:
Follow the following steps to get this started on your server (only Unix, no Windows):

  • Checkout from Jaxl trunk
    sabhinav:~# sudo svn checkout jaxl-read-only
  • Enter checked out directory
    sabhinav:~# cd jaxl-read-only
  • Enter your server admin IM contact details
    sabhinav:~# sudo vim config.ini.php
    define('JAXL_SERVER_ADMIN', '[email protected]');
  • Enable server administration extension
    sabhinav:~# sudo vim index.php
    include_once("jaxl4serveradmins.class.php"); // include_once("jaxl.class.php");
  • Wroom Wroom, start Jaxl
    sabhinav:~# sudo php index.php
    Starting TLS Encryption...
    Attempting PLAIN Authentication...
    Starting Session...
    Requesting Feature List...
    Requesting Roster List...
    Setting Status...

Tail the jaxl log file in case you are facing any difficulties in the setup.

sabhinav:~# tail -f log/logger.log

You should also consider adding /proc/ directory under open_basedir in php.ini file.

Is it working?
If all is well configured server admins will start getting notifications every 10 seconds which is default value for JAXL_SERVER_LOAD_POLL_INTERVAL.
Jaxl4serveradmins.class.php example screenshot for system load

Writing custom notifications
Above I demonstrate how we can use XMPP and PHP to generate real time system notification. However, you may want to modify parseServerLoad() method to send notifications only when the server load exceeds a certain value. You may also want to add other methods which can notify you of various System and Server level parameters in a similar fashion. Below are a few useful system administration commands:

sabhinav:~# free -m
sabhinav:~# vmstat 1 20

Is it really real time?
Since, parseServerLoad() method polls for /proc/loadavg file every 10 seconds, this is not exactly real time. However you can configure JAXL_SERVER_LOAD_POLL_INTERVAL to make it poll faster. You can also use libevent extension in PHP to make it real time in real sense.

Do let me know if you write any interesting functionality, I will be more than happy to include it as a part of current extension.


  1. Pingback: Get real time system & server load notification on any IM using … | Coder Online

  2. Pingback:

  3. Pingback: Abhinav Singh’s Blog: Get real time system & server load notification on any IM using PHP and XMPP | Webs Developer

  4. Pingback: Abhinav Singh’s Blog: Get real time system & server load notification on any IM using PHP and XMPP | Development Blog With Code Updates :

  5. Pingback: Tweets that mention Get real time system & server load notification on any IM using PHP and XMPP | Abhi's Weblog --

  6. Pingback: » Archive » Messagerie instantanée avec PHP & XMPP

  7. Pingback: Recibe información del servidor por IM (Jabber) | Sentido Web

  8. Pingback: Messagerie instantanée avec PHP & XMPP |

  9. iknow it uses XMPP to send messages, but I do not know how to use this at all. It is my understanding that I should be able to make a bot which chats for me when I am away if I were to create my own client page, which would parse the chats with my data. Where would I begin if I wanted to create a custom client, and how could I make it parse messages and autorespond in a set manner? My intended usage: autoresponder for when I am AFK, with a decent AI (which I can make.)

    1. For all your custom needs you will have to code it down for yourself. Jaxl is a library which hides xmpp internals from it’s users, by providing convinient methods to write your app.

      AI etc all should be written by the developers. If you need customization, kindly contact me through email. Hopefully I will be able to help you out a bit.

    1. kblack

      I am just following the instructions, set up all the config in the includes (the same credentials work fine with a Perl bot I created) and when I issues ‘php index.php” I get the php relocation error.

    2. kblack


      Thanks for trying to help me, I discovered the problem is centered around how OpenSSL is handled within the framework.

      2 problems, first the script includes can’t accurately detect the OS and thinks its Windows, which is strange because it is vanilla CentOS 5.

      Second is the includes aren’t getting along with OpenSSL within the jaxl framework.

      PHP behaves normally within all other instances. So I think I have to mutate the script somewhere. When I figure that out I’ll post it back here…

  10. Pingback: Delicious Bookmarks for March 20th through March 21st « Lâmôlabs

  11. Pingback: Links for 2010-01-19 | Stéphane Thibault

Comments are closed.