systeminformation icon indicating copy to clipboard operation
systeminformation copied to clipboard

Average number is 0 for CPU

Open StrangerGithuber opened this issue 2 years ago • 5 comments

Describe the bug I am trying to get in real time the cpu usage statistic, ram usage statistic, HHD/SSD usage statistic and internet usage statistic. When I am trying to get the avg load for the cpu then it is 0 everytime. I did request the currentLoad but it is not correct with the task manager.

To Reproduce Steps to reproduce the behavior:

  1. I installed the systeminformation package
  2. I did import the package as in the example documentation: const si = require('systeminformation');
  3. I did use this code:
setInterval(function () {
       si.currentLoad().then(data => {
           console.log(data.avgLoad);
       })
   }, 1000)

Current Output I get this:

{
  avgLoad: 0,
  currentLoad: 62.72130329980883,
  currentLoadUser: 57.91704762696368,
  currentLoadSystem: 4.546587981048957,
  currentLoadNice: 0,
  currentLoadIdle: 37.27869670019117,
  currentLoadIrq: 0.25766769179619314,
  rawCurrentLoad: 7546,
  rawCurrentLoadUser: 6968,
  rawCurrentLoadSystem: 547,
  rawCurrentLoadNice: 0,
  rawCurrentLoadIdle: 4485,
  rawCurrentLoadIrq: 31,
  cpus: [
    {
      load: 100,
      loadUser: 78.77906976744185,
      loadSystem: 18.217054263565892,
      loadNice: 0,
      loadIdle: 0,
      loadIrq: 3.003875968992248,
      rawLoad: 1032,
      rawLoadUser: 813,
      rawLoadSystem: 188,
      rawLoadNice: 0,
      rawLoadIdle: 0,
      rawLoadIrq: 31
    },
    {
      load: 20.3,
      loadUser: 15.6,
      loadSystem: 4.7,
      loadNice: 0,
      loadIdle: 79.7,
      loadIrq: 0,
      rawLoad: 203,
      rawLoadUser: 156,
      rawLoadSystem: 47,
      rawLoadNice: 0,
      rawLoadIdle: 797,
      rawLoadIrq: 0
    },
    {
      load: 100,
      loadUser: 100,
      loadSystem: 0,
      loadNice: 0,
      loadIdle: 0,
      loadIrq: 0,
      rawLoad: 1000,
      rawLoadUser: 1000,
      rawLoadSystem: 0,
      rawLoadNice: 0,
      rawLoadIdle: 0,
      rawLoadIrq: 0
    },
    {
      load: 25,
      loadUser: 20.3,
      loadSystem: 4.7,
      loadNice: 0,
      loadIdle: 75,
      loadIrq: 0,
      rawLoad: 250,
      rawLoadUser: 203,
      rawLoadSystem: 47,
      rawLoadNice: 0,
      rawLoadIdle: 750,
      rawLoadIrq: 0
    },
    {
      load: 100,
      loadUser: 100,
      loadSystem: 0,
      loadNice: 0,
      loadIdle: 0,
      loadIrq: 0,
      rawLoad: 1000,
      rawLoadUser: 1000,
      rawLoadSystem: 0,
      rawLoadNice: 0,
      rawLoadIdle: 0,
      rawLoadIrq: 0
    },
    {
      load: 26.573426573426573,
      loadUser: 21.878121878121878,
      loadSystem: 4.695304695304695,
      loadNice: 0,
      loadIdle: 73.42657342657343,
      loadIrq: 0,
      rawLoad: 266,
      rawLoadUser: 219,
      rawLoadSystem: 47,
      rawLoadNice: 0,
      rawLoadIdle: 735,
      rawLoadIrq: 0
    },
    {
      load: 100,
      loadUser: 100,
      loadSystem: 0,
      loadNice: 0,
      loadIdle: 0,
      loadIrq: 0,
      rawLoad: 1000,
      rawLoadUser: 1000,
      rawLoadSystem: 0,
      rawLoadNice: 0,
      rawLoadIdle: 0,
      rawLoadIrq: 0
    },
    {
      load: 32.732732732732735,
      loadUser: 23.423423423423422,
      loadSystem: 9.30930930930931,
      loadNice: 0,
      loadIdle: 67.26726726726727,
      loadIrq: 0,
      rawLoad: 327,
      rawLoadUser: 234,
      rawLoadSystem: 93,
      rawLoadNice: 0,
      rawLoadIdle: 672,
      rawLoadIrq: 0
    },
    {
      load: 100,
      loadUser: 98.49849849849849,
      loadSystem: 1.5015015015015014,
      loadNice: 0,
      loadIdle: 0,
      loadIrq: 0,
      rawLoad: 999,
      rawLoadUser: 984,
      rawLoadSystem: 15,
      rawLoadNice: 0,
      rawLoadIdle: 0,
      rawLoadIrq: 0
    },
    {
      load: 18.8,
      loadUser: 15.6,
      loadSystem: 3.2,
      loadNice: 0,
      loadIdle: 81.2,
      loadIrq: 0,
      rawLoad: 188,
      rawLoadUser: 156,
      rawLoadSystem: 32,
      rawLoadNice: 0,
      rawLoadIdle: 812,
      rawLoadIrq: 0
    },
    {
      load: 100,
      loadUser: 100,
      loadSystem: 0,
      loadNice: 0,
      loadIdle: 0,
      loadIrq: 0,
      rawLoad: 1000,
      rawLoadUser: 1000,
      rawLoadSystem: 0,
      rawLoadNice: 0,
      rawLoadIdle: 0,
      rawLoadIrq: 0
    },
    {
      load: 28.1,
      loadUser: 20.3,
      loadSystem: 7.8,
      loadNice: 0,
      loadIdle: 71.89999999999999,
      loadIrq: 0,
      rawLoadUser: 203,
      rawLoadSystem: 78,
      rawLoadNice: 0,
      rawLoadIdle: 719,
      rawLoadIrq: 0
    }
  ]
}

Expected behavior Giving the correct avg value.

Environment (please complete the following information):

  • systeminformation package version: 5.9.2
  • OS: Windows 10 Pro x64
  • OS Build: 19043.1237
  • Hardware CPU: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz 3.70 GHz
  • Hardware Motherboard: MSI Z370 TOMAHAWK (MS-7B47)

Additional context I don't know if it is the right method to check the CPU, Memory and other components load which could be seen in the task manager. If there is better method then I am open to every methods.

StrangerGithuber avatar Sep 16 '21 15:09 StrangerGithuber

@StrangerGithuber as described in the docs (https://systeminformation.io/processes.html), avgLoadis currently not supported for windows. If you have an Idea, what value would be appropriate for that (and how to get this), I would of course consider to implement and add this here.

sebhildebrandt avatar Sep 16 '21 16:09 sebhildebrandt

Ah ok. Unfortunately I can't say much how it should be done. I am not a pro programmer sadly. I hope someone can give a suggestion for you. :)

StrangerGithuber avatar Sep 16 '21 17:09 StrangerGithuber

@sebhildebrandt if you're fine with 3rd party node modules, you could try using this node module I found.

And then do some variable and if statement trickery to differentiate the windows loadavg code from the Unix loadavg code, use the windows loadavg only if process.platform equals some win32 or something like that

The only problem is the module may be out of date...I'm currently not near a PC to test it.

But, if it works, It'd probably the best way to get loadavg on windows, if you decide you want to implement the feature...

At least, that's what I'd do lol

dehydratedpotato avatar Sep 19 '21 16:09 dehydratedpotato

@BitesPotatoBacks Thank you, I already thought of implementing it the same way ... there is only one downside, As this has to keep its own stats (for the last 15 min) you need to call this regularly to get correct values. I still think that having it this way is better then nothing ;-) ... will try to come up with a solution as soon as I have time for it.

sebhildebrandt avatar Sep 20 '21 06:09 sebhildebrandt

I'd just like to mention the fact that native os.cpus() returns idle/tick values properly on windows which can be used to calculate the CPU usage over a certain span of time, though it would need to be done periodically in the background.

ShapeMess avatar Mar 03 '22 14:03 ShapeMess