Posts

Showing posts with the label 監察網站狀況

IT筆記:使用Google Apps Script 監察網站狀況

Image
參考了這個網站( Spreadsheet Dev )的文章,使用 Google Sheet 和改動了一些 Google Apps Script程式碼,用來監察網站的服務是否正常。 步驟如下 :  創建一個 Google 表格電子表格來跟踪網站隨時間的狀態 登錄谷歌賬戶並在瀏覽器輸入 https://spreadsheet.new 來創建新的 Google Sheet 將新的試算表命名為 Web Monitor 並加上四個欄位 "Url " , "Date", "Status", "Load time" 在Google試算表菜單選擇「擴充功能」,Apps Script。 重新命名專案命名為 web monitor 20221216,並創建兩個分別命名為 checkWebsiteStatus 及 SetTimeTrigger的 Google Script。 輸入需要監察網站的地址url及接收電郵的帳戶。 function checkWebsiteStatus() {   let url = " https://www.abovethcloud.com/ ";   // Record time so we can track how long the website   // takes to load.   let start = new Date();   let response = UrlFetchApp.fetch(url, {muteHttpExceptions: true});   let end = new Date();   let responseCode = response.getResponseCode();   let loadTimeMs = end - start;   // Record a log of the website's status to the spreadsheet.   SpreadsheetApp.getActive().getSheetByName("Data").appendRow([url, start, responseCode, loadTimeMs]);   // Se...