Get the uptime of your website for free using Google Spreadsheets

You can monitor the uptime of your website for free using Google Spreadsheets.

Example:

How to do it

The first step is to create a new Google Spreadsheet and add a new script:

Tools > Script editor

By default the name of the function is myFunction(), you can rename it to upTime().

In a few words, the function will call a desire URL and get the response:

  • if( valid_response) status = 1; // Ok
  • if(!valid_response) status = 0; // Ko

Coding the function

javascript
function upTime() {  
  
    // Sheet names
    var sheetNames = ['Nomoresheet', 'Erikmartinjordan'];

    // Defining the URL's to look uptime
    var uptimeURLs = ['https://nomoresheet.es', 'https://erikmartinjordan.com'];

    // Iterating through responses
    for(var i = 0; i < uptimeURLs.length; i ++){
    
        // Getting sheet
        var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetNames[i]);
        
        // Getting last column and row
        var lastRow = sheet.getLastRow();
        var lastCol = sheet.getLastColumn();
        
        // Setting time of execution
        var date = Utilities.formatDate(new Date(), SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "dd/MM/yyyy HH:mm");
        
        // Writting day and time in sheet
        sheet.getRange(lastRow + 1, 2).setValue(date);
        
        try{
        
            // Getting response code
            var response = UrlFetchApp.fetch(uptimeURLs[i]);
            
            // If response is ok, write it in Excel
            sheet.getRange(lastRow + 1, 3).setValue(1);
            
        }
        catch(e){
        
            // If response is not ok, write it in Excel 
            sheet.getRange(lastRow + 1, 3).setValue(0);
            
            // Sending email
            if(sheet.getRange(lastRow - 1, 3).getValue() === 0 && sheet.getRange(lastRow, 3).getValue() === 0){
                MailApp.sendEmail(email, subject, message);
            }
            
        }
        
    }
  
}

Now you will need to define a time trigger to execute the function repeatedly. From the script window:

Edit > Current project's triggers

Add the time interval (minute, hour, day) that you wish.

And that's it, you can download the repo from GitHub as well.

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.