Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID
Advertise on

In this Discussion

PHP/JSON low end box Status Monitor script (no database)

PHP/JSON low end box Status Monitor script (no database)

RaymiiRaymii Member
edited July 2012 in General


How it works:

On every server you set a cronjob for the client script. This is a bash script which outputs a bunch of text formatted as json, like this:

{ "Services": { "lighttpd" : "running","sshd" : "running","syslog" : "running","munin-node" : "running" }, "Disk" : { "total" : "15360M", "used" : "10820M", "free" : "4541M", "percentage" : "71%" }, "Load" : "0.01,", "Users logged on" : "0", "Uptime" : "29days,", "Free RAM" : "204", "Total RAM" : "256", "IPv4" : "", "Hostname" : "vps5", "External IPv4" : " ","JSON" : "close" }

The server has a php script (the one in the demo) which does the magic to make it look good. Since I discovered this JSON thing I'm almost in love with it :p. It also has a script to get the json files from every monitored server. (in my case rsync, but I might do it via wget).


  • Implement a better down-check. If it cannot fetch a json file from a server, it should output a time since when it is down.
  • Implement apt-get package update checks (and yum, is someone donates me a centos server :P )
  • Source will be released some time in these two weeks, MIT/X11 license from

Ideas? Comments? please tell me :)

Quis custodiet ipsos custodes? -


  • This is very cool. Great web interface!

    Thanked by 1Raymii
  • fanfan Member

    Nice interface, good job!

    Thanked by 1Raymii
  • klikliklikli Member
    edited July 2012

    Why not just build the communication on top of HTTP?

  • PADPAD Member

    Very nice work.

    Will wait for release.

    Thanked by 1Raymii
  • RaymiiRaymii Member

    @klikli The client is a bash script which is called by cron on a set interval. The communication is now liek this because the JSON stat files do not have to be public now. If I do it over HTTP, it also would require a lot of javascript (i think) and I'm not very skilled in that.

    Quis custodiet ipsos custodes? -
  • AsimAsim Member
    edited July 2012

    Cool, waiting for the release.


    • The DETAIL should be for one particular VPS only
    • Alternate row colors
    • An email-friendly version of this so that it can be emailed to admin etc
    I blog at
  • RaymiiRaymii Member
    edited July 2012


    Ok, just did some coding. I've added a package update monitor, network traffic stats and a little ping thingie.

    Detail page is now not functional, that will be a history page in any of the next releases. @Asim your feedback is the thing I'll work on next.


    Can any of you test this code to check for package updates:


    echo `apt-get -s upgrade | awk '/[0-9]+ upgraded,/ {print $1}'`


    echo `pacman -Sy 1>/dev/null 2>&1; pacman -Qu | wc -l`

    yum (centos/fedora/RHEL)

    echo `yum -q check-update | wc -l`

    Does it output a number of packages that can be updated? (or 0 for no packages)? I've got no other non-debian boxes atm to test...

    Quis custodiet ipsos custodes? -
  • littleguylittleguy Member
    edited July 2012

    @Raymii said: yum (centos/fedora/RHEL)

    Ran the command, seems to work on both CentOS 5 and 6:

    CentOS 5: [[email protected] ~]# echo yum -q check-update | wc -l 17

    CentOS 6: [[email protected]~]# echo yum -q check-update | wc -l 125

    Reminds me I really could use a yum update. :)

  • eastoncheastonch Member
    edited July 2012
    [email protected]:~/backup# echo `apt-get -s upgrade | awk '/[0-9]+ upgraded,/ {print $1}'`

    deb 6 32b

    Security Consultant

  • cool

  • DamianDamian Member

    I like it. I'm anxious for the source; i'd like to add a current-network-transfer graph.

    Thanked by 1eastonch
  • RaymiiRaymii Member

    Release planned for tomorrow (monday). Here's the readme file as a teaser:

    Ray-Mon - A PHP/Bash decentralized server monitoring script

    Ray-Mon is a server monitoring script written in PHP and Bash, utilizing JSON for decentralized monitoring.
    It is free / libre open source software currently supporting debian and CentOS.


    • Ping monitor for websites
    • Monitors unlimited servers
    • No central monitoring server
    • Currently monitors:
      • Uptime
      • Load
      • RAM Usage
      • Disk Usage
      • Network traffic
      • User activity
      • Services (by checking if Linux Process runs)
    Planned features include:
    • Individual host monitor history
    • Graphs?

    Installation & Configuration

    Download the .zip package and unzip it to a directory of choice.


    Edit the script to include the services you want, change the default four ones or add new ones by copying these lines:

    if ps ax | grep -v grep | grep $SERVICE > /dev/null; then echo -n "\"$SERVICE\" : \"running\","; else echo -n "\"$SERVICE\" : \"not running\","; fi

    Note that the last service to monitor has to be without a comma for valid JSON.

    Edit the network interface you want to use for IP address display


    or iface="eth0"

    (first one is for OpenVZ virtualized containers)

    Also edit the interface you want to use for traffic monitoring


    or iface2="eth0"

    (first one again is for OpenVZ virtualized containers. If you are on XEN or bare metal hardware you probably use eth0, eth1 or bond0 or something.)

    Last thing to edit is fot the package updates. If you are on debian/ubuntu you can leave it as it is, if you are on Fedora/CentOS/RHEL, or Arch Linux you have to comment the debian line and uncomment the arch or RHEL/CentOS/Fedora (yum) line.

    Now save the script and put it on all the servers you want to monitor. A good location is to put it in a users home directory, or the root home directory:

    $~ scp -P 22 [email protected]:/home/user/

    Repeat that for all the servers you want to monitor. SSH into every server and add a ROOT cronjob to run the script. If you do not run the cronjob as root you cannot monitor package updates.

    */5 * * * * /home/user/ > /var/www/stat.json

    As you can see this cronjob redirects the output to the wwwroot so that the monitor server can get the stat.json file. If you do not want the stat.json file to be seen publicly you can setup restrictions in your webserver config or pump the stat.json files over via scp or rsync to the monitoring server.

    Verify if the client runs correct:

    #~ ./

    If you get a permission error you might need to chmod it to make it executable:

    #~ chmod +x ./

    The server needs a webserver and PHP install working. You can verify your PHP install via <?php phpinfo(); ?>. If you do not know how to setup a LAMP stack I recommend you to take a look on HowToForge.

    Copy the stat.php file and the to your wwwroot. Edit the file to get the status files from the hosts were you've setup the script. You can move the file to a non-wwwroot location, but make sure it can run. Also edit the paths were needed.

    wget -O /var/www/server1.json
    chmod 777 /var/www/server1.json

    This script should also run from a cronjob, every 5 minutes or so.

    */5 * * * * /var/www/

    Now edit the stat.php file. The host config is at the bottom of the file. For every host needed add a line like this:

    <?php shortstat("server1.json",""); ?>

    Were the first parameter is the json status file (here it is in the same directory (/var/www/). PHP must be able to read the file. The second parameter is the hostname. (it is used to display errors if it cannot read the json file)

    For the ping monitoring you need to edit the Ping section in the stat.php file. To add a host, add or edit a line like this:

    echo ping("", 80, 5);

    Were the first parameter is the host you want to ping (ip or hostname), the second is the port (usually 80) and the last parameter is the timeout in seconds.

    Now save the file and see if it runs. If so, you get a nice monitoring panel, and if not you might see some errors.

    In case of errors, verify that the file runs correctly, and make sure it can get the files from the clients.


    Copyright (c) 2012 Remy van Elst

    Permission is hereby granted, free of charge, to any person obtaining a copy

    of this software and associated documentation files (the "Software"), to deal

    in the Software without restriction, including without limitation the rights

    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

    copies of the Software, and to permit persons to whom the Software is

    furnished to do so, subject to the following conditions:


    The above copyright notice and this permission notice shall be included in

    all copies or substantial portions of the Software.









    Ray-Mon uses the excellent HTML5 Kickstart framework for the interface, found at It is inspired by the LowEndTalk community, by Munin, Nagios, OpenStatus and Pingdom.

    Feel free to suggest features, ask questions and leave comments using the comment form on the page. Or send me a message via the contact form.

    Quis custodiet ipsos custodes? -
    Thanked by 1Maounique
  • @Raymii

    Are we allowed to modify the interface for example use bootstrap? - Freelance Sysadmin.

  • RaymiiRaymii Member

    @martip07 Yes, you can do everything unless the license says you cannot ;)

    Quis custodiet ipsos custodes? -
    Thanked by 1martip07
  • azizmbazizmb Member
    edited July 2012

    Very cool. Look forward to toying with it tomorrow :)

  • I like LET :) Thanks Remy :) M

    Extremist conservative user, I wish to preserve human and civil rights, free speech, freedom of the press and worship, rule of law, democracy, peace and prosperity, social mobility, etc. Now you can draw your guns.

  • be nice to have this up on github :)

    Thanked by 1djvdorp
  • tuxtux Member
    [[email protected] ~]$ echo `apt-get -s upgrade | awk '/[0-9]+ upgraded,/ {print $1}'`
    -- empty line --

    Lubuntu 12.10 32 bit

  • Looking forward to this!

    Security Consultant

  • Looking really good, I might use this :)

  • RaymiiRaymii Member
    edited July 2012

    @tux it probably means you have no updates...

    @FRCorey I might put it up on gitorious

    Quis custodiet ipsos custodes? -
  • @Raymii said: @FRCorey I might put it up on gitorious

    GitLab is awesome too (If you want to host it yourself)

    Check my blog for more cool *nix tips & tricks!

  • RaymiiRaymii Member
    edited July 2012

    Beta release 1

    For all of you to test and try out. if it works well, I'll do an official release on Not github or gitorious yet, probably after first final.


    Download .zip of Ray-Mon v0.0.1 BETA

    Quis custodiet ipsos custodes? -
    Thanked by 1HalfEatenPie
  • HalfEatenPieHalfEatenPie Member
    edited July 2012

    You forgot a http:// there

    Catalyst Host - Pie Approved!
    Thanked by 2djvdorp eastonch
  • RaymiiRaymii Member


    Quis custodiet ipsos custodes? -
  • Thanks bud

    Catalyst Host - Pie Approved!
  • AndriAndri Member

    Will try. Good job and thank you @Raymii. :)

    I trust Namesilo for my domains. Use DOLLARLESS for $1 discount.
  • RaymiiRaymii Member

    I'd like to see some of the setups you guys/gals make. If you don't mind, please post some links?

    Quis custodiet ipsos custodes? -
  • @Raymii: I haven't used it yet (i'm still setting up some servers). Sorry bud D:

    Catalyst Host - Pie Approved!
  • Hosted with torqhost, Loving this!

  • RaymiiRaymii Member

    @undisclosedp Nice :)

    I however noticed a bug in the HDD space part. It is fixed now in the download file, so you might want to update stat.php (redownload the zip and replace stat.php). Typo's in the used and free space.

    Quis custodiet ipsos custodes? -
  • happelhappel Member
    edited July 2012

    Nice script.

    The text for HDD usage seems the wrong way around btw.

    edit: few seconds late :-)

  • RaymiiRaymii Member

    @happel I noticed that, it fixed just now, was already fixed on my server but forget to git push...

    Quis custodiet ipsos custodes? -
  • Nice one, I was wondering about that! Uploaded the fresh file!

    Are you taking feature suggestions?

  • support mongodb redis?

  • azizmbazizmb Member

    So finally got it running on my web server(s). Just a tip, I noticed that the .json file gets its file permissions set to 0777 after being downloaded. I'd recommend you change this to 0755 for safety reasons. I even got it running with it as 0700 (both the script and the files share the same nginx ownership).

  • RaymiiRaymii Member

    @undisclosedp You can always ask, and if I can do it i might.

    @azizmb Correct, but my permission setup is a little different.

    @ynzheng I've got no experience with MongoDB or Redis, and the point of this is to use no seperate database (software). The code is open, you can always hack it in yourself.

    Quis custodiet ipsos custodes? -
  • Just a note on the Cron settings. - Generating Json files will/can take a few seconds (depending on actions) - Calling a Wget at the same time will sometimes download the old file

    Suggested solution: - In add a sleep argument for 3-5 seconds before first Wget call

  • RaymiiRaymii Member

    @telephone Correct, I've noticed that also. My solution was to let the cronjob run every 6 minutes. If the timeservers are synced then it will give a collision indeed.

    Quis custodiet ipsos custodes? -
  • syamansyaman Member

    This looks amazing!

    Is there a way to not display the IP address of each monitored server?

  • azizmbazizmb Member
    edited July 2012


    Comment out the line in stat.php that reads: echo "IPv4: " . $json_a['IPv4'] . "<br />";

    And if you want it so that the IP Address doesn't even get recording in the json files; comment out the parts under the IP Areas in the script (# local IP and #external IP).

  • RaymiiRaymii Member

    @syaman @azizmb correct method of removing it. You should make sure that the json file is still valid after tweaking it (via for example) because if not PHP will not be able to parse it.

    Does anyone has more comments, feature request or example setups? How does it work for you?

    The problem I had with openstatus was the high IO load on the database (openstatus-server), and with my scripts I do not see that. How is that with other installs?

    Quis custodiet ipsos custodes? -
  • RaymiiRaymii Member

    @kbar what do you mean by that?

    Quis custodiet ipsos custodes? -
  • happelhappel Member
    edited July 2012

    probably this, the third column isn't even


  • RaymiiRaymii Member

    That would require some css, but would be possible. I had hoped that the html5 kickstart framework took care of that. Anyone ported it to bootstrap yet?

    Quis custodiet ipsos custodes? -
  • Apols for resurrecting an older thread, but is this happening to anyone else?


    Top two seem to be fine, but bottom shows "Users: day" and "Load: load"

    "We are in a prison drama. This is like The Shawshank Redemption, only with more tunneling through shit and no fucking redemption."
  • Happens to me as well.

  • is anyone still using this?

Sign In or Register to comment.