How to use the measured-core.Histogram function in measured-core

To help you get started, we’ve selected a few measured-core 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 sematext / sematext-agent-docker / lib / aggregator.js View on Github external
Aggregator.prototype.update = function (timestamp, name, value, calcDiff) {
  this.lastUpdate = Date.now()
  if (isNaN(value)) {
    return
  }
  if (this.metrics[name] === undefined) {
    this.metrics[name] = new Measured.Histogram()
  }
  if (!this.lastValues[name]) {
    this.lastValues[name] = {value: value, ts: timestamp}
  }

  if (calcDiff === true) {
    var diff = value - this.lastValues[name].value
    if (diff < 0) {
      // container stop might have caused a reset of metric value.
      this.lastValues[name].value = 0
    } else {
      this.metrics[name].update(diff, timestamp)
      this.lastValues[name] = {value: value, ts: timestamp}
    }
  } else {
    this.metrics[name].update(value, timestamp)
github yaorg / node-measured / packages / measured-reporting / lib / registries / SelfReportingMetricsRegistry.js View on Github external
getOrCreateHistogram(name, dimensions, publishingIntervalInSeconds) {
    validateHistogramOptions(name, dimensions, publishingIntervalInSeconds);

    let histogram;
    if (this._registry.hasMetric(name, dimensions)) {
      histogram = this._registry.getMetric(name, dimensions);
    } else {
      histogram = new Histogram();
      const key = this._registry.putMetric(name, histogram, dimensions);
      this._reporters.forEach(reporter => reporter.reportMetricOnInterval(key, publishingIntervalInSeconds));
    }

    return histogram;
  }