/ domm

I hack Perl for fun and profit.

Follow me on twitter!
Atom Icom ... on Atom!
13.07.2017: Using a DarkPAN with Carton
02.01.2017: Vienna.pm Meeting dates for 2017 (as calculated by Perl 6)
23.12.2016: Announcing Plack::Middleware::PrettyException
13.09.2016: Too dumb for TCP
04.09.2016: Alpine Perl Workshop 2016
26.08.2016: Things I learned at the European Perl Conference 2016 in Cluj
26.07.2016: App::TimeTracker::Command::TellSlack
18.06.2016: Announcing Plack::App::ServiceStatus

Here's a small piece of code I hacked together monday afternoon to better monitor our apps: Plack::App::ServiceStatus

It's a Plack app (not a middleware!) similar to the various Plack*Status modules (but most of them are middlewares). Plack::App::ServiceStatus returns some JSON indicating if your server is up and running (boring) and if your server can actually reach other services (not so boring, I hope). While you can (and should) monitor each and every service on it's own, sometimes it's also interesting if various services can actually talk with each other (especially if they are not running on the same server or data center).

Usage, straight from the POD:

use Plack::Builder;
use Plack::App::ServiceStatus;

my $schema = YourApp::Schema->connect( ... ); # DBIx::Class
my $es     = Search::Elasticsearch->new;

my $status_app = Plack::App::ServiceStatus->new(
    app           => 'your app',
    DBIC          => $schema,
    Elasticsearch => $es,
);

builder {
  mount "/_status" => $status_app;
  mount "/" => $your_app;
};

Now you can check the status:

curl http://localhost:3000/_status  | json_pp
{
   "app" : "Your app",
   "started_at" : 1465823638,
   "uptime" : 42,
   "checks" : [
      {
         "status" : "ok",
         "name" : "Your app"
      },
      {
         "name" : "Elasticsearch",
         "status" : "ok"
      },
      {
         "name" : "DBIC",
         "status" : "ok"
      }
   ]
}

I really like the concept of writing small, self-contained Plack applications, and then stitching them together via Plack::Builder. And if you use the wonderful OX (or some other Bread::Board based toolkit), initiating all of the services is a breeze!

Thanks to Farhad Shahbazi for providing some feedback and discussion while implementing, and to Validad for supporting Open Source Software.

Comments (via disqus)

12.06.2016: Recent activity
24.04.2016: Announcing Alpine Perl Workshop 2016
>>>>>>>>>>