How to use the @pm2/io.histogram function in @pm2/io

To help you get started, we’ve selected a few @pm2/io examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keymetrics / app-playground / app.js View on Github external
traffic: true
  }
})


/**
 * Probe system #1 - Histograms
 *
 * Measuring the event loop delay
 */

const TIME_INTERVAL = 1000

let oldTime = process.hrtime()

const histogram = io.histogram({
  name: 'Loop delay',
  measurement: 'mean',
  unit: 'ms'
})

setInterval(() => {
  const newTime = process.hrtime()
  const delay = (newTime[0] - oldTime[0]) * 1e3 + (newTime[1] - oldTime[1]) / 1e6 - TIME_INTERVAL
  oldTime = newTime
  // Now we update the metric
  histogram.update(delay)
}, TIME_INTERVAL)


/**
 * Probe system #2 - Metrics