Created
December 29, 2017 09:12
-
-
Save soudai/be7205b297badb2fe0aca81cfd05acd7 to your computer and use it in GitHub Desktop.
Send Endpoint JSON of Google Apps Script to Mackerel service metric
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 scriptProp = PropertiesService.getScriptProperties().getProperties(); | |
var mackerelApiKey = scriptProp.MACKEREL_API_KEY; | |
var serviceName = scriptProp.MACKEREL_SERVICE_NAME; | |
var BaseURL = scriptProp.BASE_URL; | |
function main() { | |
var mackerelPostRes = postMackerelServiceMetric(mackerelApiKey, serviceName, getEndpointJSON()); | |
} | |
function postMackerelServiceMetric(apiKey, serviceName, payload) { | |
var url = "https://mackerel.io/api/v0/services/" + serviceName + "/tsdb"; | |
return UrlFetchApp.fetch( | |
url, | |
{ | |
"contentType" : "application/json", | |
"method" : "post", | |
"headers" : { | |
"X-Api-Key" : apiKey | |
}, | |
"payload" : JSON.stringify(JSON.parse(payload)), | |
"muteHttpExceptions" : true | |
} | |
); | |
} | |
function getEndpointJSON() { | |
var url = BaseURL; | |
var options = { | |
'method' : 'get', | |
'muteHttpExceptions' : true | |
} | |
Logger.log(url); | |
Logger.log(UrlFetchApp.fetch(url, options)); | |
return UrlFetchApp.fetch(url, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
以下のようなフォーマットでJSONを吐くエンドポイントを作ればそれをMackerelのサービスメトリックに投稿してくれる。
PHPだと以下のような感じ
nameは
Custom
の部分がグラフ名で.
以降がグラフのラベル名になる。