最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JS `os` method not returning any data in Vite project - Stack Overflow

programmeradmin1浏览0评论

My goal is to collect and graph CPU usage for the host. I have a simple Vite project and am using vite-plugin-node-polyfills to try to use the os JS method. However, it just returns an empty object. I don't have any console errors. Why isn't the method able to access the underlying host?

vite-config.js:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import nodePolyfills from 'vite-plugin-node-polyfills'

// /config/
export default defineConfig({
  plugins: [
    react(), 
    nodePolyfills({
      globals: {
        Buffer: true, 
        global: true,
        process: true,
      },
      protocolImports: true,
    })],
})

My various console logs/dirs to test the data:

  console.dir(os.cpus, { depth: null })
  let cpus1 = os.cpus().length
  let avg = os.loadavg()[0]/cpus1
  let load = os.loadavg()
  console.log("load "+load)
发布评论

评论列表(0)

  1. 暂无评论