Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.