Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

CPU load API values meaning


cincura.net
 Share

Question

The REST API documentation says the values in `cpuLoad` are percent in user/system/idle. But when I check the API, the values do not look like a percent at all.

 

Please login or register to see this code.

 

What is the unit? Can somebody shed some light on it?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Some calculation require to get actual CPU load in %

May be that could help ( code from @AutoFrank 

Please login or register to see this link.

 scene)

-- CPU
  local cpu0_puser      = tonumber(response.cpuLoad[1].cpu0.user)
  local cpu1_puser      = tonumber(response.cpuLoad[2].cpu1.user)
  local cpu0_pnice      = tonumber(response.cpuLoad[1].cpu0.nice)
  local cpu1_pnice      = tonumber(response.cpuLoad[2].cpu1.nice)    
  local cpu0_psystem    = tonumber(response.cpuLoad[1].cpu0.system)
  local cpu1_psystem    = tonumber(response.cpuLoad[2].cpu1.system)
  local cpu0_pidle      = tonumber(response.cpuLoad[1].cpu0.idle)
  local cpu1_pidle      = tonumber(response.cpuLoad[2].cpu1.idle)
  local cpu0_PREVTOTAL  = (cpu0_puser + cpu0_pnice + cpu0_psystem + cpu0_pidle)
  local cpu1_PREVTOTAL  = (cpu1_puser + cpu1_pnice + cpu1_psystem + cpu1_pidle)
  fibaro:sleep(1000)
  
  response1, returnCode = api.get("/diagnostics")
  local cpu0_user       = tonumber(response1.cpuLoad[1].cpu0.user)
  local cpu1_user       = tonumber(response1.cpuLoad[2].cpu1.user)
  local cpu0_nice       = tonumber(response1.cpuLoad[1].cpu0.nice)
  local cpu1_nice       = tonumber(response1.cpuLoad[2].cpu1.nice)
  local cpu0_system     = tonumber(response1.cpuLoad[1].cpu0.system)
  local cpu1_system     = tonumber(response1.cpuLoad[2].cpu1.system)
  local cpu0_idle       = tonumber(response1.cpuLoad[1].cpu0.idle)
  local cpu1_idle       = tonumber(response1.cpuLoad[2].cpu1.idle)
  local cpu0_TOTAL      = (cpu0_user + cpu0_nice + cpu0_system + cpu0_idle)
  local cpu1_TOTAL      = (cpu1_user + cpu1_nice + cpu1_system + cpu1_idle)
  local cpu0_Percentage = ( ( (cpu0_TOTAL - cpu0_PREVTOTAL) - (cpu0_idle - cpu0_pidle) ) / (cpu0_TOTAL - cpu0_PREVTOTAL) ) * 100
  local cpu1_Percentage = ( ( (cpu1_TOTAL - cpu1_PREVTOTAL) - (cpu1_idle - cpu1_pidle) ) / (cpu1_TOTAL - cpu1_PREVTOTAL) ) * 100
  cpu0_Percentage = round(cpu0_Percentage)
  cpu1_Percentage = round(cpu1_Percentage)

Link to comment
Share on other sites

  • 0
3 hours ago, cag014 said:

Some calculation require to get actual CPU load in %

May be that could help ( code from @AutoFrank 

Please login or register to see this link.

 scene)

-- CPU
  local cpu0_puser      = tonumber(response.cpuLoad[1].cpu0.user)
  local cpu1_puser      = tonumber(response.cpuLoad[2].cpu1.user)
  local cpu0_pnice      = tonumber(response.cpuLoad[1].cpu0.nice)
  local cpu1_pnice      = tonumber(response.cpuLoad[2].cpu1.nice)    
  local cpu0_psystem    = tonumber(response.cpuLoad[1].cpu0.system)
  local cpu1_psystem    = tonumber(response.cpuLoad[2].cpu1.system)
  local cpu0_pidle      = tonumber(response.cpuLoad[1].cpu0.idle)
  local cpu1_pidle      = tonumber(response.cpuLoad[2].cpu1.idle)
  local cpu0_PREVTOTAL  = (cpu0_puser + cpu0_pnice + cpu0_psystem + cpu0_pidle)
  local cpu1_PREVTOTAL  = (cpu1_puser + cpu1_pnice + cpu1_psystem + cpu1_pidle)
  fibaro:sleep(1000)
  
  response1, returnCode = api.get("/diagnostics")
  local cpu0_user       = tonumber(response1.cpuLoad[1].cpu0.user)
  local cpu1_user       = tonumber(response1.cpuLoad[2].cpu1.user)
  local cpu0_nice       = tonumber(response1.cpuLoad[1].cpu0.nice)
  local cpu1_nice       = tonumber(response1.cpuLoad[2].cpu1.nice)
  local cpu0_system     = tonumber(response1.cpuLoad[1].cpu0.system)
  local cpu1_system     = tonumber(response1.cpuLoad[2].cpu1.system)
  local cpu0_idle       = tonumber(response1.cpuLoad[1].cpu0.idle)
  local cpu1_idle       = tonumber(response1.cpuLoad[2].cpu1.idle)
  local cpu0_TOTAL      = (cpu0_user + cpu0_nice + cpu0_system + cpu0_idle)
  local cpu1_TOTAL      = (cpu1_user + cpu1_nice + cpu1_system + cpu1_idle)
  local cpu0_Percentage = ( ( (cpu0_TOTAL - cpu0_PREVTOTAL) - (cpu0_idle - cpu0_pidle) ) / (cpu0_TOTAL - cpu0_PREVTOTAL) ) * 100
  local cpu1_Percentage = ( ( (cpu1_TOTAL - cpu1_PREVTOTAL) - (cpu1_idle - cpu1_pidle) ) / (cpu1_TOTAL - cpu1_PREVTOTAL) ) * 100
  cpu0_Percentage = round(cpu0_Percentage)
  cpu1_Percentage = round(cpu1_Percentage)

These calculations look strange... isn't nice a part of user? It's usually 0 on the HC3 but anyway... and doesn't the percentage calculation always return 100?  sorry, didn't see the 'p' prefix of idle the variables.. but should nice be included?

 

Edited by jgab
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...