This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

CPU Load Log as Trend
#1
Hello everyone,

Does anyone know how could I get the CPU load as a 2byte value (virtual object) and then make a Trend Log with a resolution of 1sec or log by delta change = 1% of CPU usage?

What I need to achieve is a historic data log from the CPU usage.

Kind regards and thank you for any help in advance
Reply
#2
This will give you load and memory
Code:
data = io.readfile('/proc/meminfo')
load = io.readfile('/proc/loadavg'):split(' ')[ 1 ]

memtotal = data:match('MemTotal:%s+(%d+)')
memavail = data:match('MemAvailable:%s+(%d+)')
memusage = math.floor((memtotal - memavail) / memtotal * 1000) / 10

log(tonumber(load), memusage)
------------------------------
Ctrl+F5
Reply
#3
(10.09.2019, 13:37)Daniel. Wrote: This will give you load and memory
Code:
data = io.readfile('/proc/meminfo')
load = io.readfile('/proc/loadavg'):split(' ')[ 1 ]

memtotal = data:match('MemTotal:%s+(%d+)')
memavail = data:match('MemAvailable:%s+(%d+)')
memusage = math.floor((memtotal - memavail) / memtotal * 1000) / 10

log(tonumber(load), memusage)


Hello Daniel.

Thank you for your reply.

I am getting values 0.24 , 0.25 ... Does this mean the CPU load is 0.24 %?
Reply
#4
No it is not percentage, it is bit more complicated in linux. Try reading this
https://www.tecmint.com/understand-linux...rformance/

To write to object just do it like that:
grp.update('1/1/1', tonumber(load))
------------------------------
Ctrl+F5
Reply
#5
(10.09.2019, 14:02)Daniel. Wrote: No it is not percentage, it is bit more complicated in linux. Try reading this
https://www.tecmint.com/understand-linux...rformance/

To write to object just do it like that:
grp.update('1/1/1', tonumber(load))

Yes I figured out how to write the value to the object but the Load average is indeed complicated. So then it will require a script to calculate properly the % of CPU load average for the last 1min.

Does anyone have a solution for this?
Reply
#6
Use this script to log CPU load to an object. Resident script sleep time controls how often load is calculated.
Code:
data = io.readfile('/proc/uptime'):split(' ')
total, idle = tonumber(data[ 1 ]), tonumber(data[ 2 ])

if prevtotal then
  deltatotal = total - prevtotal
  deltaidle = idle - previdle

  load = math.floor((1 - (deltaidle / deltatotal)) * 100 + 0.5)
  grp.update('32/0/0', load)
end

prevtotal, previdle = total, idle
Reply
#7
Thank you Admin. As always works perfectly.  Smile
Reply
#8
(11.09.2019, 06:33)admin Wrote: Use this script to log CPU load to an object. Resident script sleep time controls how often load is calculated.
Code:
data = io.readfile('/proc/uptime'):split(' ')
total, idle = tonumber(data[ 1 ]), tonumber(data[ 2 ])

if prevtotal then
  deltatotal = total - prevtotal
  deltaidle = idle - previdle

  load = math.floor((1 - (deltaidle / deltatotal)) * 100 + 0.5)
  grp.update('32/0/0', load)
end

prevtotal, previdle = total, idle

What datatype would appropiate for this output`?

Best regards, Jørn.
Reply
#9
5.001 - 0..100%
Reply


Forum Jump: