API /v2 How do I get CPU Usage Average?

Joined
Jan 4, 2024
Messages
1
Hey everybody!

I am using some of my free time to link some of my systems together and have started working on the Truenas server in my home. I would like to get the average CPU usage between all cores using the V2 API. For memory, I used /stats/get_data to get the current RAM usage. For CPU, I found aggregation-cpu-average which contains the types:

Code:
"aggregation-cpu-average": [
    "cpu-interrupt",
    "cpu-softirq",
    "cpu-user",
    "cpu-system",
    "cpu-idle",
    "cpu-nice",
    "cpu-steal",
    "cpu-wait"
  ]


This is where I am currently stuck. Am I on the right path, if so which field should I use? If not, please point me in the right direction.

Thanks all in advance! :smile:
 

jasonhorner

Cadet
Joined
Feb 18, 2024
Messages
3
Yes, you're on the right path with /stats/get_data for RAM and exploring aggregation-cpu-average for CPU. To calculate average CPU usage across all cores, subtract cpu-idle from the sum of cpu-user, cpu-system, cpu-nice, cpu-steal, and cpu-wait. This represents active CPU time divided by total time, giving you a percentage as the average.
 
Top