Skip to content

Instantly share code, notes, and snippets.

@theeye-io
Created May 10, 2017 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theeye-io/ffa1fbd26d1177faf8080b7ff01659f1 to your computer and use it in GitHub Desktop.
Save theeye-io/ffa1fbd26d1177faf8080b7ff01659f1 to your computer and use it in GitHub Desktop.
Response Time Check using curl and nodejs
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