Let triggers = ScriptApp.getProjectTriggers() If you want it to run more frequently, feel free to adjust the interval based on your use case. The function setUpTrigger() below creates a trigger that runs the function checkWebsiteStatus() every four hours. To do this, we will set up a time-based trigger. The final step is to run the function checkWebsiteStatus() periodically to monitor your website's status. Step 3 - Set up a time-based trigger to periodically monitor the website's status If the function works, you should see a new row in your spreadsheet with the results of the check. Try running the function checkWebsiteStatus() and confirm that it is working correctly. Let response = UrlFetchApp.fetch(url, instead.` Record time so we can track how long the website SpreadsheetApp.getActive().getSheetByName("Data").appendRow() The specific line where you need to make the change is: Replace with the email address that should be notified when a HTTP response code other than 200 (success) is received.Įither name the sheet in your spreadsheet Data or use the name of your sheet in the code below. This assumes that the Apps Script code that powers the UrlFetchApp feature is stable and it does not become slower or faster over time.įinally, if a response code other than 200 is received, an error notification is sent via email to notify someone who can investigate the potential issue further.ĭo not forget to replace placeholders in the code below This can be used as a proxy for how quickly your website loads. It also tracks the number of milliseconds that elapsed between when it starts the UrlFetchApp call and when it receives the response code. The function checkWebsiteStatus() uses UrlFetchApp to try loading your website and records the response code it receives in the spreadsheet. The next step is to create an Apps Script function to check whether your website is up or not and record this information in your spreadsheet. Load time: The time taken for your website to load in milliseconds. Status: The status code returned by your website when the Apps Script code tried to load it. The code we will write in step #2 will assume that your spreadsheet has a sheet called Data containing three columns:ĭate: The date when the status of your website was checked. The URL will create a new Google Sheets spreadsheet? Step 3 - Set up a time-based trigger to periodically monitor the website's statusĬreate a Google Sheets spreadsheet to track your website's status over time. Step 2 - Use Apps Script to check if the website is up and record this information in your spreadsheet Step 1 - Create a Google Sheets spreadsheet to track the website's status over time Triggers (especially time-based triggers)ģ steps to implement a website monitoring solution using Google Sheets and Apps Script Sending email from Google Sheets using MailApp In addition, this tutorial assumes that you're familiar with: If you're new to Apps Script, I've written a detailed tutorial on learning to code with Google Sheets and Apps Script. This tutorial assumes that you're familiar with both Google Sheets and Apps Script. In this tutorial, I'll show you how simple it is to set this up. There are many website monitoring services available that will help you automate this process but it is very easy to implement a simple website uptime monitoring solution using just a few lines of Apps Script code. Doing this manually can be tedious and you might forget to check your website regularly. If you maintain a website, it is important to monitor it periodically to check if it is still up and working correctly. In this tutorial, I will show you how to monitor your website using Apps Script. Website monitoring using Google Sheets and Apps Script
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |