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

My goal is to collect and graph CPU usage for the host. I have a simple Vite project and am using vite-

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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745118116a4612253.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信