os.cpus().map(cpu => cpu.times)
function displayResults (results) { if (quiet === false) console.log('==========') const benchNames = Object.keys(results) for (var i = 0; i < benchNames.length; i += 1) { console.log(`${benchNames[i].toUpperCase()} benchmark averages`) const benchmark = results[benchNames[i]] const loggers = Object.keys(benchmark) for (var j = 0; j < loggers.length; j += 1) { var logger = benchmark[loggers[j]] var average = sum(logger) / logger.length console.log(`${loggers[j]} average: ${average.toFixed(3)}ms`) } } if (quiet === false) { console.log('==========') console.log( `System: ${type()}/${platform()} ${arch()} ${release()}`, `~ ${cpus()[0].model} (cores/threads: ${cpus().length})` ) } }
this.broker.Promise.resolve() .then(() => cpuUsage().then(res => { this.set(METRIC.OS_CPU_UTILIZATION, res.avg); try { const cpus = os.cpus(); this.set(METRIC.OS_CPU_TOTAL, cpus.length); this.set(METRIC.OS_CPU_USER, cpus.reduce((a,b) => a + b.times.user, 0)); this.set(METRIC.OS_CPU_SYSTEM, cpus.reduce((a,b) => a + b.times.sys, 0)); cpus.forEach((cpu, index) => { this.set(METRIC.OS_CPU_INFO_MODEL, cpu.model, { index }); this.set(METRIC.OS_CPU_INFO_SPEED, cpu.speed, { index }); this.set(METRIC.OS_CPU_INFO_TIMES_USER, cpu.times.user, { index }); this.set(METRIC.OS_CPU_INFO_TIMES_SYS, cpu.times.sys, { index }); }); } catch(err) { // silent } })) .catch(() => { // silent this.logger.warn("Unable to collect CPU usage metrics.", err); }) .then(() => { this.logger.debug(`Collected common metric values in ${duration.toFixed(3)} msec.`); })
totalmem: os.totalmem(), freemem: os.freemem(), cpus: os.cpus(), network_interfaces: os.networkInterfaces(), nodejs_version: process.version,
const workerCount = Number.isInteger(instances) && instances > 0 ? instances : os.cpus().length;
os .cpus() .map(function(cpu) { return cpu.model }) .reduce(function(o, model) { if (!o[model]) o[model] = 0 o[model]++ return o }, {})
app.get('/info', function (req, res) { var info = { client: Config.Discogs.UserAgent, uptime: os.uptime(), cpu: os.cpus(), archicture: os.arch(), type: os.type() }; res.send(pretty(info)); });
os.cpus().forEach((value, index) => { console.log("Forking:", index); const worker = cluster.fork(); works.push(worker); });
function getSystemCpuAvgLoad() { var cpus = os.cpus(); var sysTotal = 0; for(var i = 0, len = cpus.length; i < len; i++) { var cpu = cpus[i], total = 0; for(var type in cpu.times) { total += cpu.times[type]; } sysTotal += ((total - cpu.times['idle']) / total); } return sysTotal / cpus.length; }
function restartThreads(count = "auto") { let threadCount = count; if(count === "auto"){ threadCount = (os.cpus().length > 3 ? Math.floor(os.cpus().length / 3) + 1 : 1) } console.log(`\x1b[35mRestarting to ${threadCount} threads\x1b[0m`) fileProcessorThreads.forEach((fork, idx) => { fork.thread.kill() }) fileProcessorThreads = [] createThreads(threadCount) }
/** * Gets CPU stats * @return {Object} CPU stats (number of CPUs and average load) * @private */ cpuStat() { const cpus = os.cpus(); // get cores count const load = os.loadavg(); // get average return { cpus: cpus.length, load, }; }
os.cpus().filter(function(cpu, index) { const hasHyperthreading = cpu.model.includes("Intel"); const isOdd = index % 2 === 1; return !hasHyperthreading || isOdd; })
totalmem: os.totalmem(), freemem: os.freemem(), cpus: os.cpus(), network_interfaces: os.networkInterfaces(), nodejs_version: process.version,