How to use measured-core - 10 common examples

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
getOrCreateMeter(name, dimensions, publishingIntervalInSeconds) {
    // todo validate options
    let meter;
    if (this._registry.hasMetric(name, dimensions)) {
      meter = this._registry.getMetric(name, dimensions);
    } else {
      meter = new Meter();
      const key = this._registry.putMetric(name, meter, dimensions);
      this._reporters.forEach(reporter => reporter.reportMetricOnInterval(key, publishingIntervalInSeconds));
    }

    return meter;
  }
github yaorg / node-measured / packages / measured-reporting / lib / registries / SelfReportingMetricsRegistry.js View on Github external
getOrCreateTimer(name, dimensions, publishingIntervalInSeconds) {
    validateTimerOptions(name, dimensions, publishingIntervalInSeconds);

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

    return timer;
  }
github kaola-fed / console-agent / old / lib / core / metrix / timer.js View on Github external
constructor(properties = {}) {
        const { duration } = properties;

        return new Timer(Object.assign({}, properties, {
            meter: new Meter({ duration })
        }));
    }
github yaorg / node-measured / packages / measured-signalfx-reporter / lib / registries / SignalFxSelfReportingMetricsRegistry.js View on Github external
getOrCreateTimer(name, dimensions, publishingIntervalInSeconds) {
    validateTimerOptions(name, dimensions, publishingIntervalInSeconds);

    let timer;
    if (this._registry.hasMetric(name, dimensions)) {
      timer = this._registry.getMetric(name, dimensions);
    } else {
      timer = new Timer({ meter: new NoOpMeter() });
      const key = this._registry.putMetric(name, timer, dimensions);
      this._reporters.forEach(reporter => reporter.reportMetricOnInterval(key, publishingIntervalInSeconds));
    }

    return timer;
  }
github yaorg / node-measured / packages / measured-node-metrics / lib / nodeOsMetrics.js View on Github external
'node.os.cpu.all-cores-avg': (updateIntervalInSeconds, sampleTimeInSeconds) => {
    updateIntervalInSeconds = updateIntervalInSeconds || 30;
    sampleTimeInSeconds = sampleTimeInSeconds || 5;

    return new CachedGauge(() => {
      return new Promise(resolve => {
        //Grab first CPU Measure
        const startMeasure = cpuAverage();
        setTimeout(() => {
          //Grab second Measure
          const endMeasure = cpuAverage();
          const percentageCPU = calculateCpuUsagePercent(startMeasure, endMeasure);
          resolve(percentageCPU);
        }, sampleTimeInSeconds);
      });
    }, updateIntervalInSeconds);
  }
};
github yaorg / node-measured / packages / measured-reporting / lib / registries / SelfReportingMetricsRegistry.js View on Github external
getOrCreateCachedGauge(
    name,
    valueProducingPromiseCallback,
    cachedGaugeUpdateIntervalInSeconds,
    dimensions,
    publishingIntervalInSeconds
  ) {
    validateCachedGaugeOptions(name, valueProducingPromiseCallback, dimensions, publishingIntervalInSeconds);

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

    return cachedGauge;
  }
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;
  }
github yaorg / node-measured / packages / measured-signalfx-reporter / lib / registries / SignalFxSelfReportingMetricsRegistry.js View on Github external
getOrCreateMeter(name, dimensions, publishingIntervalInSeconds) {
    this._log.error(
      'Meters will not get reported using the SignalFx reporter as they waste DPM, please use a counter instead'
    );
    return new NoOpMeter();
  }
github yaorg / node-measured / packages / measured-reporting / lib / registries / SelfReportingMetricsRegistry.js View on Github external
getOrCreateCounter(name, dimensions, publishingIntervalInSeconds) {
    validateCounterOptions(name, dimensions, publishingIntervalInSeconds);

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

    return counter;
  }