Created
May 10, 2017 03:40
-
-
Save theeye-io/ffa1fbd26d1177faf8080b7ff01659f1 to your computer and use it in GitHub Desktop.
Response Time Check using curl and nodejs
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 exec = require('child_process').exec; | |
var url = process.argv[2]; | |
var threshold = parseFloat(process.argv[3]); | |
var eventName; | |
var state; | |
var cmd = 'curl -o /dev/null -s -w %{time_total} ' + url; | |
console.log('running ' + cmd); | |
console.log('checking response time for ' + url + ' is below => ' + threshold); | |
exec(cmd, function(err, stdout, stderr){ | |
var responseTime; | |
var state; | |
responseTime = parseFloat( stdout.replace(',','.') ); | |
if ( !stdout || isNaN(responseTime) ) { | |
state = 'failure'; | |
} else { | |
state = (responseTime >= threshold) ? 'failure' : 'success'; | |
} | |
console.log( JSON.stringify({ state: state, data: { responseTime: String(responseTime) } }) ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment