Table of contents
Introduction
I started freelancing as a web developer last year. When people talk about web development, it is usually a lot about how to gather requirements from clients, how to code, how to make good websites, etc.
But what happens post delivery is not discussed as much, especially if you are a solo developer making relatively low traffic websites.
Well, bad things can happen post-delivery.
Sites go down, SSL certificates expire, domains expire, plugins become outdated, libraries get major updates, or your host obliterates your server during a regular maintenance... Phew!
If you have 1 website, you can open it in a browser to test if it is online. But when you're taking care of 10 websites or you have to keep track of microservices, you quickly run into issues. Plus, how long can you even stay up and test if your site is up?
It's not fun to get calls from clients telling you that their site is down. To solve this "site is down" issue, I made "lemme-know". It's a CLI tool that can run locally as well as in the cloud and uses nodemailer to send emails.
Yes, there are plenty of sophisticated monitoring tools out there, but I wanted something minimal with no frills. No complex dashboards, no visitor tracking, nothing. It's a simple script that sends you an email (or a notification) if your site is down and it's free.
A CLI tool that lets you do this per website, called is-up already exists. lemme-know consumes the is-up API and extends it to monitor multiple sites and send emails if one is down.
Let's dig in!
Installation
Make sure you have the latest stable version of Node.
npm i lemme-know -g
Usage
Your list of websites and email settings are supplied via a json file. Feel free to copy the file below and edit it:
{
"websites": [
"https://test.example.com",
"http://example.com",
"http://another.example.com"
],
"mail": {
"host": "smtp.example.com", //could be smtp.gmail.com
"port": 587,
"secure": false,
"auth": {
"user": "you@example.com", // could be your gmail username
"pass": "supersecretstuff" // could be your gmail password
},
"subject": "Website(s) may be down!",
"sender": "you@example.com",
"receiver": "you@example.com, yourdev@example.com"
}
}
You might have to add an app password to Google to run this on a server. Basically Google generates a different password for your account. Just follow the first step over here if you need to.
Run locally
lemme-know settings.json
You won't receive any emails in this mode. You'll be able to see the status of your websites directly in the terminal like this:
Stay informed via email
lemme-know -e settings.json
The -e flag asks lemme-know to send an email
You can use the "-s" flag to run lemme-know in silent mode
If you are running this on a server, you might want to use "screen" to keep the process running even if you logout of the session. You can refer to this article to learn how you can do that.
If you want to kill the process, just find and use the process ID:
kill -9 <pid>
I suggest using Gmail SMTP. Gmail has a generous email sending limit. You could create a new Gmail account for the sole purpose of doing this if you want. That way you don't compromise on security. You are free to use any service you have available, of course.
If you just want to test if the email part works, you can run the code in test mode instead.
lemme-know --test
This will output a preview URL where you can see the email that would have been sent to you if a site was down.
Important note: I have not tested this on Windows. Feel free to open an issue on Github or open a PR to support Windows.
Change the frequency
By default, lemme-know checks every 30 minutes if a site is down. That should work for most low traffic websites.
However, if you need to up the frequency of checks, you can do:
lemme-know -es settings.json -r 10
The -r flag sets the time in minutes between checks. Now the check will happen every 10 minutes.
More information
This tool is not intended for high traffic websites. It's intended for freelancers or small agencies who are managing low traffic websites.
I also highly suggest that you don't ping websites you don't own. Most good sites have DoS checks in place and your IP will get blacklisted.
If your site has DoS checks in place then whitelist the IP you are running the tool on. You can then increase the frequency too.
What if your monitoring server goes down?
It's probably the first thing you think of after you go through the post. To tackle this problem, we could work on a distributed lemme-know. Basically, you could setup a chain of fallback servers in case the primary monitoring server goes down. If the primary server fails, the 2nd in the chain gets activated. If the 2nd one fails, the third server gets activated, and so on.
The cool part about this is that you can make any of your existing servers run lemme-know in the background. No need to spin up extra servers for this.
What next?
The tool currently works on Linux and I haven't tested it on Windows (or Windows servers for that matter).
There most definitely are bugs lurking around. This is just an alpha version. Feel free to fork the code and make it better.
Enjoyed the article? High five!
Or you could, you know, drop me a star on Github.
Check out the Github repo here.
Top comments (0)