Skip to content

Instantly share code, notes, and snippets.

@theeye-io
Created November 23, 2016 18:10
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/6435db167f4a681d1e9a7359d87aef6d to your computer and use it in GitHub Desktop.
Save theeye-io/6435db167f4a681d1e9a7359d87aef6d to your computer and use it in GitHub Desktop.
check response time with curl and nodejs
var exec = require('child_process').exec;
var url = process.argv[2];
var threshold = parseFloat(process.argv[3]);
var cmd = 'c:\\theeye\\theeyecore\\mingw64\\bin\\curl.exe -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,state;
responseTime=parseFloat(stdout);
if ( !stdout || isNaN(responseTime) ) {
state='failure';
event='command_failure'; // aca podemos asumir fallo del comando porque no devolvio el valor numerico esperado
} else {
state=(responseTime>=threshold) ? 'failure' : 'success';
event=state; // para que disparece el evento failure o success. si se pone otra cosa no dispara evento
}
console.log( JSON.stringify({ state:state, data:{responseTime:responseTime} }) );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment