openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

[Systeminfo] CPU average load for last 1, 5, 15 minutes #2451

Closed spy0r closed 7 years ago

spy0r commented 7 years ago

Hi,

i wanted to ask why the average load in the systeminfo binding is shown as "percent" if created via Paper UI. In the documentation its description is "Load in percents for the last x minute(s)" as well.

In my mind the average load is related to the number of cores/threads and has nothing to do with percent, except you normalized the values to the number of cores, which i doubt.

Please see: https://en.wikipedia.org/wiki/Load_(computing) as well as https://community.openhab.org/t/custom-theme-in-habpanel-2-1-example/31100/11?u=spy0r

Thanks for explanation or correction :) Stef

BClark09 commented 7 years ago

Hi @spy0r systeminfo, uses the oshi library. For system load, it uses this method or this method for non-oracle jvm

A value of 0.0 means that all CPUs were idle during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running 100% of the time during the recent period being observed

Indeed, it looks like % is the correct term to use.

spy0r commented 7 years ago

okay, but even if it's already calculated to all cpu cores - how can a value of 1 (in percent) define 100%?

1.0 percent is per definition 0,01*value. So it can't be correct?

BClark09 commented 7 years ago

The method returns a number from 0 to 1, this is equal from 0 to 100%. A basic example:

You have 2 CPUs, between the first and second time the process checks for usage:

CPU 1 - Was being used 30% of the time CPU 2 - Wasn't being used at all.

The method returns 0.15 The binding forwards this value as a percentage, 15%

spy0r commented 7 years ago

No the binding doesn't show 15%, it would show 0.15% - that's the mistake i wanted to show

You can say 0.01 equals 1%, but you can't set the unit of 0.01 to percent, because percent means "per cent", "per 100".

if you generally multiply the value you get from this method with 100, than you can use the unit percent.

BClark09 commented 7 years ago

Apologies, I completely missed the system load average part.

Yes it would seem that the % value has been appended where it should not have been. This is a display error only, the value is correct.

In binding terms, this unit should not have a default pattern: https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.systeminfo/ESH-INF/thing/channels.xml#L284

spy0r commented 7 years ago

now we're talking, thanks for the confirmation

BClark09 commented 7 years ago

I've made the above pull request which should resolve the problem.

spy0r commented 7 years ago

Does that request change the documentation as well?

martinvw commented 7 years ago

No, I saw some documentation change but I now realize that that was documentation of the code, if you would like you can of course create your own pr for that.

That would be this file: https://github.com/openhab/openhab2-addons/blob/master/addons/binding/org.openhab.binding.systeminfo/README.md