Last active
December 18, 2015 14:08
-
-
Save ayakix/5794763 to your computer and use it in GitHub Desktop.
自分で管理しているサービスのレスポンスタイムを計測し,設定時間以上に遅い場合には,アラートメールを飛ばすスクリプト
http://blog.ayakix.com/2013/06/google-apps-script.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BASE_URL = "http://hogefuga.com"; | |
var DEFAULT_LIMIT = 200; | |
var MAIL_ADDRESS = "[email protected]"; | |
var checkApiMap = { | |
'/api1' : DEFAULT_LIMIT, | |
'/api2' : DEFAULT_LIMIT, | |
'/api3' : 300, | |
} | |
function sendMail(overApiMap) { | |
var title = "#alert some api exceed the limit response time" | |
var msg = "" | |
for (var api in overApiMap) { | |
msg += api + "\t" + overApiMap[api] + "\n" | |
} | |
if (msg != "") { | |
MailApp.sendEmail(MAIL_ADDRESS, title, msg); | |
} | |
} | |
function doCheck() { | |
var overApiMap = {}; | |
for (var api in checkApiMap) { | |
var url = BASE_URL + api | |
var before = new Date(); | |
var res = UrlFetchApp.fetch(url); | |
var after = new Date(); | |
var responseTime = after - before; | |
if (res.getResponseCode() !== 200) { | |
overApiMap[api] = -1; | |
} else if (responseTime > checkApiMap[api]){ | |
overApiMap[api] = responseTime; | |
} | |
} | |
sendMail(overApiMap); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment