How to use the measured-core.CachedGauge 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 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;
  }