Google apps script

Create your own Sites Uptime Monitor

As we face the daily need of checking the uptime for our domains and it is a bit hectic to go and check each and every site daily, and if you own a bit number of sites, then it is a headache to check status manually every day.

So Either you have to run for some online tools, sites or do it manually or make your own uptime checker.

We are here to take you through a detailed process to create your own domain uptime monitor. Which will monitor your sites and mail you if any site is down and then you can check your site and activate it.

We will use google apps script to create this tool just like we created the mail merge to send emails in bulk with Gmail.

Pre-Requisites:

A Gmail account, it can be free or paid, doesn’t matter.

Set Uptime Monitor

It’s time for setting up your own uptime monitor




Like last time, I am going to help you to set up each and every module of this uptime monitor, Just follow the mentioned steps one by one:

  1. Open your Google Drive.
  2. Create a spreadsheet with name “Uptime Monitor.”
  3. Create the below header for the page.
    Site URL Status Error
  • Site URL: here You will put all domain/site links which need to be monitored.
  • Status: This column will show the status of the sites
  • Error: This column will show the error message for the down sites.




  1. Now Go to Tools > Script editor and name the new app script page “Uptime Monitor.”
  2. Remove everything and Paste the Below script in the page.
function UptimeMonitor() {

var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var data = sheets[0].getDataRange().getValues();

for(i=1;i<data.length;i++)
{
try{
var responsecode = UrlFetchApp.fetch(data[i][0]).getResponseCode();
if(responsecode == 200){
sheets[0].getRange(i+1, 2).setValue("OK");
}
}
catch(e)
{
Logger.log("Alert:" + e.message);
sheets[0].getRange(i+1, 3).setValue(Logger.getLog());
Logger.clear();
}

if(sheets[0].getRange(i+1, 2).getValue() != "OK")
{
MailApp.sendEmail("Put your email address","The website" + " " + data[i][0] + " " + "is down", "Please check with the registrar or hosting and take necessary actions to curb the issue");
}
}
}

function onOpen(){
SpreadsheetApp.getUi().createMenu("Check Uptime").addItem("Execute", "UptimeMonitor").addToUi();
}

It should look like this

READ  Mail Merge : Send mails in bulk from your Gmail account

Once you paste the code, on line 23rd, replace ‘Put your email address’ with the mail address, where you want to send the mail for the downtime of sites and save the app script.

Now go to the spreadsheet and refresh it. Now you will see a newly added menu item ‘check uptime’ on your sheet.

Click on check uptime > Execute and then it will check the status for all listed websites in column A and show you the site uptime status in status Column, and if the site is down, it will send a mail to the mentioned email address and show you the error message in the Error column.

When you run this script for the first time, it will ask you for some permissions like accessing your spreadsheet/ drive, etc. Just approve it, and it will be saved.

Automate the Script

Now, lets go and automate this process. Apps script will run every day by its own and send you a mail if any listed site is down.

We will going to set triggers for this app script. So follow the mentioned steps and set your own trigger for your script.

Go to Uptime monitor app script page. (uptime monitor sheet > tools > script editor).

Go to the menu of app script page, click Edit >  Current Project’s triggers.

Now in the popup, Click on the Add a new trigger and it will open a window to select the options to set the trigger.

Choose ‘UptimeMonitor’ , ‘Time-Driven’ , ‘Day timer’, ‘Midnight to 1am’  respectivelly and click on Save.

READ  Pick Random Members from Team with Apps script

And you are done, now this script will run automatically every day at 1 AM midnight and send you mail if the site is down. You can also choose another timing as per your conveinience.

You are done, so set your own uptime monitor and put your sites in the Site URL column and get free from the headache of checking the uptime status manully.

Fell free to comment in case of any issues.

About the author

Learning Hub Editorial Team

We are a team of tech enthusiasts who find Google Apps and its features intriguing. Let us know your views if you find us helpful.

Leave a Comment