Howdy, Stranger!

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


PHP/JSON low end box Status Monitor script (no database)
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

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

RaymiiRaymii Member
edited July 2012 in General

DEMO

http://raymii.nl/stat.php

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" : "209.141.58.74/32", "Hostname" : "vps5", "External IPv4" : " 209.141.58.74 ","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).

Plans

  • 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 http://raymii.org

Ideas? Comments? please tell me :)

«1

Comments

  • This is very cool. Great web interface!

    Thanked by 1Raymii
  • fanfan Veteran

    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.

  • AsimAsim Member
    edited July 2012

    Cool, waiting for the release.

    Feedback

    • 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
  • RaymiiRaymii Member
    edited July 2012

    Update!

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

    http://raymii.nl/stat.php

    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.

    Request

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

    debian

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

    arch

    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...

  • 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:
    [root@test ~]# echo yum -q check-update | wc -l
    17

    CentOS 6:
    [root@main~]# echo yum -q check-update | wc -l
    125

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

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

    deb 6 32b

  • 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.

    Features

    • 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.

    Client

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

    SERVICE=lighttpd
    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

    iface="venet0:0"
    

    or
    iface="eth0"

    (first one is for OpenVZ virtualized containers)

    Also edit the interface you want to use for traffic monitoring

    iface2="venet0:0"
    

    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 client.sh [email protected]:/home/user/client.sh
    

    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/client.sh > /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:

    #~ ./client.sh
    

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

    #~ chmod +x ./client.sh
    
    Server

    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 statget.sh to your wwwroot. Edit the statget.sh file to get the status files from the hosts were you've setup the client.sh script. You can move the statget.sh file to a non-wwwroot location, but make sure it can run. Also edit the paths were needed.

    wget -O /var/www/server1.json http://server1.nl/stat.json
    chmod 777 /var/www/server1.json
    

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

    */5 * * * * /var/www/statget.sh
    

    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","server1.nl"); ?>
    

    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("raymii.org", 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 statget.sh file runs correctly, and make sure it can get the files from the clients.

    License

    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.

    #

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN

    THE SOFTWARE.

    Ray-Mon uses the excellent HTML5 Kickstart framework for the interface, found at 99lime.com.
    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.

    Thanked by 1Maounique
  • @Raymii

    Are we allowed to modify the interface for example use bootstrap?

  • RaymiiRaymii Member

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

    Thanked by 1martip07
  • azizmbazizmb Member
    edited July 2012

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

  • MaouniqueMaounique Host Rep, Veteran

    I like LET :)
    Thanks Remy :)
    M

  • be nice to have this up on github :)

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

    Lubuntu 12.10 32 bit

  • Looking forward to this!

  • 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

  • @Raymii said: @FRCorey I might put it up on gitorious

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

  • 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 Raymii.org.
    Not github or gitorious yet, probably after first final.

    DOWNLOAD!!!

    Download .zip of Ray-Mon v0.0.1 BETA

    Thanked by 1HalfEatenPie
  • HalfEatenPieHalfEatenPie Veteran
    edited July 2012

    You forgot a http:// there

    Thanked by 2djvdorp eastonch
  • RaymiiRaymii Member

    fixed

  • Thanks bud

  • AndriAndri Member

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

  • RaymiiRaymii Member

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

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

  • Hosted with torqhost, Loving this! http://46.22.208.210/raymon/stat.php

Sign In or Register to comment.