function measureLoopDelay() {
  // how much time has actually elapsed in the loop beyond what
  // setTimeout says is supposed to happen. we use setTimeout to
  // cover multiple iterations of the event loop, getting a larger
  // sample of what the process is working on.

  // we use Math.max to handle case where timers are running efficiently
  // and our callback executes earlier than `ms` due to how timers are
  // implemented. this is ok. it means we're healthy.
  const lag = Math.max(0, msTimeDiff(start) - sampleInterval) / sampleInterval * 1000; // Loop lag per second

  lags.push(lag);
  if (sampleDataFlag || lags.length > lagCount) {
    sampleDataFlag = true;
    const evictedLag = lags.shift();
    avgLag += (lag - evictedLag) / lagCount;
  } else {
    // Incremental averageing - http://math.stackexchange.com/questions/106700/incremental-averageing
    avgLag += (lag - avgLag) / lags.length;
  }

  start = process.hrtime();
  clearTimeout(timeout);
  timeout = setTimeout(measureLoopDelay, sampleInterval);
}
/**
 * Measure system stats and push to datadog.
 */
Measure system stats and push to datadog.
Measure system stats and push to datadog .
function measureLoopDelay() {
  const lag = Math.max(0, msTimeDiff(start) - sampleInterval) / sampleInterval * 1000; 
  lags.push(lag);
  if (sampleDataFlag || lags.length > lagCount) {
    sampleDataFlag = true;
    const evictedLag = lags.shift();
    avgLag += (lag - evictedLag) / lagCount;
  } else {
    avgLag += (lag - avgLag) / lags.length;
  }
  start = process.hrtime();
  clearTimeout(timeout);
  timeout = setTimeout(measureLoopDelay, sampleInterval);
}
function measureLoopDelay ( ) { const lag = Math . max ( 0 , msTimeDiff ( start ) - sampleInterval ) / sampleInterval * 1000 ; lags . push ( lag ) ; if ( sampleDataFlag || lags . length > lagCount ) { sampleDataFlag = true ; const evictedLag = lags . shift ( ) ; avgLag += ( lag - evictedLag ) / lagCount ; } else { avgLag += ( lag - avgLag ) / lags . length ; } start = process . hrtime ( ) ; clearTimeout ( timeout ) ; timeout = setTimeout ( measureLoopDelay , sampleInterval ) ; }
Measure system stats and push to datadog.
Measure system stats and push to datadog .
// how much time has actually elapsed in the loop beyond what // setTimeout says is supposed to happen. we use setTimeout to // cover multiple iterations of the event loop, getting a larger // sample of what the process is working on. // we use Math.max to handle case where timers are running efficiently // and our callback executes earlier than `ms` due to how timers are // implemented. this is ok. it means we're healthy. // Loop lag per second // Incremental averageing - http://math.stackexchange.com/questions/106700/incremental-averageing