An easy to install uptime monitor

Original – by Freek Van der Herten – 4 minute read

A few weeks ago we released our uptime and ssl certificate monitor. It's written in PHP and distributed as a Laravel package. If you're familiar with Laravel that's all fine, but if you have no experience with that (kick ass) framework, it's a bit difficult to get started with using our uptime package. That's why we've released a stand alone version of the package. There's no Laravel knowledge required to use it. In this post I'd like to show you how easy it is to set up.

Uptime and ssl certificate checks

Let's first recap what our uptime monitor can do. First and foremost it can perform an uptime check on all your sites. When one of your sites goes down, you'll get a notification via mail and/or Slack. This is how such a notification looks like:

When your site comes back up you'll get a notification too.

You can customise various aspects of the uptime check in the configuration file.

The package can also notify you when the ssl certificate of one of your sites will expire of has expired. Here's how that looks like in Slack.

How to install the monitor app

Installing the uptime monitor is now very easy. Just issue this command on your server:

composer create-project spatie/uptime-monitor-app

That command will pull in a copy of Laravel 5.3 with the laravel-uptime-monitor preinstalled. When it's done it'll display some instructions you need to follow to complete the installation

The first thing you'll need to do is adding this command to your cron table so it'll run every single minute:

php <installation path>/artisan schedule:run

This will make sure that both the uptime and the certificate check will run regularly.

Next, in order to be notified via Slack you need to create a webhook on the Slack site. The url of that webhook needs to be saved in the notifications.slack key in the configuration.php file in the root of the app.

With that out of the way you're ready to monitor some sites. Let's add a monitor for our company site Perform this command in the root of the monitor app.

php artisan monitor:create

The monitor app will now regularly perform an uptime check for that site. Whenever you add an url that starts with https the certificate check will also be performed for that site.

If you run php artisan monitor:list after a few minutes you'll seen a screen not unlike this one.

Of course you can add as many monitors as you like, behind the scenes the app will use Guzzle's concurrent requests feature to very quickly check multiple sites at once.

Want to stop monitoring a site for a while, just disable it. If you permanently want to stop monitoring a site, just delete the monitor.

// temporarily stop monitoring the site
php artisan monitor:disable

// start monitoring it again
php artisan monitor:enable

// delete the monitor
php artisan monitor:delete

By default the application will store all monitors in an sqlite database located at database.sqlite in the root of the app. It'll contain a single table called monitors. Here's the documentation on which fields it contains and which fields may be manually modified.

We hope this standalone version of the uptime monitor is much easier to use for those without any Laravel knowledge. If you have any questions about it or have an idea on how to improve it, just add a comment below this post, or even better, open up an issue on the uptime-monitor-app repo on GitHub. Be sure to also take a look at this list of packages we previously made.

Stay up to date with all things Laravel, PHP, and JavaScript.

Follow me on Twitter. I regularly tweet out programming tips, and what I myself have learned in ongoing projects.

Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.