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

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

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 :)

Quis custodiet ipsos custodes?
http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
«1

Comments

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

    Selling multiple 2000-user GApps :) Shoot me a message to make an offer.

  • 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?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • 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...

    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • 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.

    Not the biggest, just the best: IPXcore
    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.

    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
    Thanked by 1Maounique
  • @Raymii

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

    http://mitihost.com/ -> Great Shared Hosting for a good $$

    https://freevps.us/ -> Great P2H Forum to get free VPS's

    http://ownnode.biz/ - > soon

  • RaymiiRaymii Member

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

    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
    Thanked by 1martip07
  • azizmbazizmb Member
    edited July 2012

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

  • I like LET :) Thanks Remy :) M

    I am only representing myself :)

  • 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 :)

    Reviews | Website | Projects (Minstall, Scripts, etc)
  • 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?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • @Raymii said: @FRCorey I might put it up on gitorious

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

    I use http://tuxlite.com to configure all my VPSes and I love it!

  • 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

    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
    Thanked by 1HalfEatenPie
  • HalfEatenPieHalfEatenPie Member
    edited July 2012

    You forgot a http:// there

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

    fixed

    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • Thanks bud

    Catalyst Host - Pie Approved!
  • 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?

    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • @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! http://46.22.208.210/raymon/stat.php

  • 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?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • 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?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • 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?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • 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 statget.sh 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 statget.sh run every 6 minutes. If the timeservers are synced then it will give a collision indeed.

    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • syamansyaman Member

    This looks amazing!

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

  • azizmbazizmb Member
    edited July 2012

    @syaman

    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 client.sh 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 http://jsonlint.org/ 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?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • RaymiiRaymii Member

    @kbar what do you mean by that?

    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • happelhappel Member
    edited July 2012

    probably this, the third column isn't even

    image

  • 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?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • RaymiiRaymii Member
    Quis custodiet ipsos custodes?
    http://raymii.org - http://sparklingnetwork.nl - Need a VPS Control Panel? http://z1s.org/ - Need a VPS that doesn't suck? http://clients.inceptionhosting.com/aff.php?aff=083
  • Apols for resurrecting an older thread, but is this happening to anyone else?

    image

    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.