New release of Plack::App::ServiceStatus

A few days ago I released version 0.910 of Plack::App::ServiceStatus, a small Plack app that can be used for health checks and general info about your app and its dependencies.

Generate buildinfo.json

The new version comes with a small script that you can use to gather some info during the build / deployment of your app, which is stored into a file (buildinfo.json), which than can be displayed by Plack::App::ServiceStatus:

 ~/$ plack_app_service_status_generate_buildinfo.pl --project path/to/repo --output path/to/deployment/buildinfo.json

I like to add this line to my build pipelines and/or Makefile.

Using Plack::App::ServiceStatus

You only need to define the Plack app, passing some static info like app name and version, the new buildinfo file, and define any checks you want to include:

 my $status = Plack::App::ServiceStatus->new(
      app           => 'your app',
      version       => Your::App->VERSION,
      buildinfo     => 'path/to/buildinfo.json'
      DBIC          => [ $schema, 'select 1' ],
      Elasticsearch => $es, # instance of Search::Elasticsearch,
  );

Then mount ServiceStatus at some convenient route, eg /_status:

 builder {
    mount "/_status" => $status->to_app;
    mount "/"        => $your_app;
  };

And when you call /_status you'll get some information about your service (uptime etc), it's dependencies (eg if we can ping the database) and all new the buildinfo:

 {
    "app" : "Your::App",
    "buildinfo" : {
      "date" : "2023-02-14T17:02:08Z",
      "git-branch" : "main",
      "git-commit" : "e8d434ab8e6ad8e93945d704ba115da149525d01"
    },
    "checks" : [
      {
        "name" : "Your::APP",
        "status" : "ok"
      },
      {
        "name" : "DBIxConnector",
        "status" : "ok"
      }
    ],
    "hostname" : "39132fc9cd48",
    "started_at" : 1676394140,
    "started_at_iso8601" : "2023-02-14T17:02:20Z",
    "uptime" : 4714,
    "version" : 0.913
  }

You can also use this endpoint for health checks, general monitoring, showing debug info in a frontend / mobile app, etc. Or just watch it and be happy that everything works!