Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@supertenant/metrics-util / src / process / ProcessMetricsSource.js
Size: Mime:
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
"use strict";const DataSource=require("../DataSource");class ProcessDataSource extends DataSource{constructor(refreshDelay){super(refreshDelay),this.previousTimestamp=Date.now(),this.previousCpuUsage=process.cpuUsage()}doRefresh(callback){const currentTimestamp=Date.now();let cpuUsageDiff;cpuUsageDiff=currentTimestamp<=this.previousTimestamp+50?{}:process.cpuUsage(this.previousCpuUsage);const previousTimestamp=this.previousTimestamp;this.previousTimestamp=currentTimestamp,this.previousCpuUsage=process.cpuUsage(),process.nextTick(()=>{callback(null,{cpuUsageDiff:cpuUsageDiff,timeDelta:currentTimestamp-previousTimestamp})})}}module.exports=exports=ProcessDataSource;