PHP Server Status Dashboard
In The Lab | Apr 8, 2013
e-works media built PHP Server Status Dashboard as an application that allows for near real-time monitoring of remote servers. As a hosting provider it can become difficult to stay up-to-date on the resources being consumed, whether an important service is running or not, software versions, and the overall health of a system when you're managing multiple servers. We built this software to help ease that pain.
We started out with 3 goals in mind. First, we wanted a quick way to check the status of each of our hosting servers without having to login to multiple control panels. Second, we wanted to be able to manage (start/restart/stop) the processes running on each of those servers. Lastly, we wanted a way to quickly see the version of the Operating System and versions of installed software. Anything else would just be icing on the cake so to speak, and when we build cakes we like the fancy icing.
The majority of our goals were fairly trivial thanks to a few bash commands and regex. Our first real road block was letting PHP manage the processes. Since these are owned by 'root', our apache process doesn't have the permissions to manage them. We definitely weren't about to give apache those types of permissions for security reasons. To overcome this we made a binary wrapper to act as the middle man between PHP and our processes. PHP calls on this wrapper, passes the info about what it wants to do, and allows the wrapper to make the system calls. Great!
By now we had a working prototype of the application that could consume the status info and even manage the system processes. Up until this point we had been working in a same-domain security sandbox, that is, our dashboard was sitting on the same server it was pulling the status from. Once we plugged in remote servers, ones that were not on the same domain as our dashboard, we realized we hadn't thought about cross-domain requests and all the pain points associated with that. Ouch. If you don't know anything about CORS, well, you're lucky because it can be a huge pain. If your data request isn't a 'simple' request you'll also need to worry about Pre-Flight. Pre-Flight is the browser's way of checking if it's even allowed to load the resource you're requesting before actually asking for the resource. Pre-Flight requests come in the form of an 'OPTIONS' header, so the server needs to be looking for that type of request and respond to it accordingly without sending any actual data back. Once all the appropriate checks and responses were in place, our prototype was fully functional!
Now that we had a fully functional prototype making cross-domain authenticated requests, we decided the typical Long Polling style of loading the data wasn't cool. We wanted to get closer to real-time data without having to make requests at a very low interval causing strain on the servers. Were we abandoning Long Polling? No, we just wanted a choice. So along side our Long Polling methods we built in some new technology known as EventSource, which is now being standardized in the HTML5 spec. What this does is make one connection to the server and keeps it open. The server then pushes data through the pipeline back to the client which is just waiting for data. The difference between this and Long Polling is EventSource is a single persistent connection where Long Polling hits the server at a specified interval to request data. The benefit of EventSource is that it's not hitting the server every few seconds with a new request.
Once our second loading style was implemented we had a finished application that met all our initial goals, and even spread some of that fancy icing on top. Whew! So we fired it up and checked all our hosting servers like a kid on Christmas day ripping into that first present. Low and behold SMTP (mail service) was down on one of our servers. We were excited to see the dashboard reporting this. One click later in the dashboard to restart the process and it was all up and running again. From idea to concept to prototype to functional application, it's what we do best.
We dont think we should be the only ones benefiting from this, so we're completely open sourcing the entire thing on Github. Go ahead and download it now to use, or fork us and push some improvements - we're happy to merge!