Read CPU and memory Usage of whole system (not JVM)

I’d like to monitor the CPU and memory usage of the whole system and not just the JVM.
Thanks for any help or source code.

Something like this should work, though it’s not guaranteed to work on every JVM:

>>> from import ManagementFactory
>>> bean = ManagementFactory.getOperatingSystemMXBean()
>>> print bean.getSystemCpuLoad() * 100.0

It relies on the returned bean being a The interface does not include getSystemCpuLoad.

I check but it doesn’t work it seems it only return JVM CPU usage.

I find some code but I cant make it work in igniton. Could you please help me on that.


OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
# What % CPU load this current JVM is taking, from 0.0-1.0
print osBean.getProcessCpuLoad()

# What % load the overall system is at, from 0.0-1.0

The code I posted is the same thing but already converted to Jython and should work in Ignition…

1 Like

I ran the code (in script console) on 7.9.12 and it returned 0.0 when CPU was ~35%

Edit: re-ran the code and it works without changing anything…

I’m not sure about re-running, but if you are running it in the script console you’re only getting the CPU usage from whatever computer is running the Designer, not necessary of the Ignition Gateway.