sberl / signalk-rpi-monitor

Signal K Node Server Plugin for Raspberry PI monitoring (based on signalk-raspberry-pi-temperature)
Apache License 2.0
2 stars 1 forks source link

Cpu utilisation return null value #5

Closed techgardeners closed 1 year ago

techgardeners commented 2 years ago

if I call the command from the shell return

pi@openplotter:~ $ sh -c "S_TIME_FORMAT=\'ISO\' mpstat -P ALL 5 1 | sed -n 4,8p" 19:00:59 all 0,75 0,00 0,50 0,05 0,00 0,10 0,00 0,00 0,00 98,59 19:00:59 0 0,81 0,00 0,81 0,00 0,00 0,40 0,00 0,00 0,00 97,98 19:00:59 1 0,60 0,00 0,20 0,00 0,00 0,00 0,00 0,00 0,00 99,20 19:00:59 2 0,80 0,00 0,60 0,20 0,00 0,00 0,00 0,00 0,00 98,40 19:00:59 3 0,80 0,00 0,40 0,00 0,00 0,00 0,00 0,00 0,00 98,80 pi@openplotter:~ $

JonyIvy commented 1 year ago

I think I have the same problem.

I just installed signalk-rpi-monitor on a RPi CM4 with OpenPlotter 3 and the plugin is generally working. The temperatures are read and send correctly. However, the values for cpu utilisation are all "null" in the data browser and on KIP and the memory utilisation doesn't show up at all.

The server log looks fine to me:

Mar 20 20:35:06 Mon, 20 Mar 2023 19:35:06 GMT signalk-rpi-monitor got cpu utilisation 20:35:06 all 6,09 0,00 1,71 0,00 0,00 0,05 0,00 0,00 0,00 92,15 20:35:06 0 6,64 0,00 1,61 0,00 0,00 0,20 0,00 0,00 0,00 91,55 20:35:06 1 5,62 0,00 2,21 0,00 0,00 0,00 0,00 0,00 0,00 92,17 20:35:06 2 7,66 0,00 1,61 0,00 0,00 0,00 0,00 0,00 0,00 90,73 20:35:06 3 4,44 0,00 1,41 0,00 0,00 0,00 0,00 0,00 0,00 94,15 Mar 20 20:35:06 Mon, 20 Mar 2023 19:35:06 GMT signalk-rpi-monitor cpu utilisation is 92,15 Mar 20 20:35:06 Mon, 20 Mar 2023 19:35:06 GMT signalk-rpi-monitor cpu utilisation core 0 is 91,55 Mar 20 20:35:06 Mon, 20 Mar 2023 19:35:06 GMT signalk-rpi-monitor cpu utilisation core 1 is 92,17 Mar 20 20:35:06 Mon, 20 Mar 2023 19:35:06 GMT signalk-rpi-monitor cpu utilisation core 2 is 90,73 Mar 20 20:35:06 Mon, 20 Mar 2023 19:35:06 GMT signalk-rpi-monitor cpu utilisation core 3 is 94,15 Mar 20 20:35:31 Mon, 20 Mar 2023 19:35:31 GMT signalk-rpi-monitor got gpu temp=64.7'C Mar 20 20:35:31 Mon, 20 Mar 2023 19:35:31 GMT signalk-rpi-monitor gpu temp is 337.85 Mar 20 20:35:31 Mon, 20 Mar 2023 19:35:31 GMT signalk-rpi-monitor got cpu 64757 Mar 20 20:35:31 Mon, 20 Mar 2023 19:35:31 GMT signalk-rpi-monitor cpu temp is 337.91 Mar 20 20:35:31 Mon, 20 Mar 2023 19:35:31 GMT signalk-rpi-monitor got memory gesamt benutzt frei gemns. Puffer/Cache verfügbar Speicher: 7999828 1172320 5127272 106660 1700236 6596188 Swap: 102396 0 102396 Mar 20 20:35:31 Mon, 20 Mar 2023 19:35:31 GMT signalk-rpi-monitor got sd 51

Could there be a problem parsing the output of the system commands because my system is set to german language? (cpu utilisation uses comma for decimal separation and mem utilisation has german text in it) Any known remedies?

sberl commented 1 year ago

Yes. It looks like the code is having problems with "," vs "." as decimal separator. I think I have a fix coming soon.

sberl commented 1 year ago

Would anyone be willing to test out the version in https://github.com/sberl/signalk-rpi-monitor/tree/comma-as-decimal It would be appreciated. Thanks.

JonyIvy commented 1 year ago

Looks good. The individual core utilisation is now shown properly. But I can't seem to get environment.rpi.cpu.utilisation to work in KIP. It's shown ok in data browser though. Only difference to the core values is that overall cpu is unit "ratio" while the individual core utilisation is "unitless".

sberl commented 1 year ago

Will try with KIP, but I suspect it has a bug that doesn't handle metadata properly. It does work properly in the "Instrument Panel" webapp that comes preinstalled with signalk.

I have an open issue to add the "units" metadata for the individual CPU cores also.

JonyIvy commented 1 year ago

The memory utilisation is still missing. It seems to get sampled, as in the log it says:

Mar 27 08:38:36 Mon, 27 Mar 2023 06:38:36 GMT signalk-rpi-monitor got memory gesamt benutzt frei gemns. Puffer/Cache verfügbar Speicher: 7999828 1649368 2943756 82844 3406704 6142968 Swap: 102396 0 102396

But no memory deltas in data browser.

sberl commented 1 year ago

Oh. Seems the code is looking for the English word "Mem" for memory. Screen scraping sucks as a way to do this. Will look for a better way.

sberl commented 1 year ago

Can someone please send me the output of: cat /proc/meminfo from a German system. From what I've read this should not be sensitive to locale and language settings.

JonyIvy commented 1 year ago

Here you go - looks very international :)

MemTotal: 7999828 kB MemFree: 1538368 kB MemAvailable: 5526776 kB Buffers: 350032 kB Cached: 3739088 kB SwapCached: 0 kB Active: 1571888 kB Inactive: 4411456 kB Active(anon): 2860 kB Inactive(anon): 2060352 kB Active(file): 1569028 kB Inactive(file): 2351104 kB Unevictable: 116232 kB Mlocked: 88 kB SwapTotal: 102396 kB SwapFree: 102396 kB Dirty: 2352 kB Writeback: 0 kB AnonPages: 2010492 kB Mapped: 945796 kB Shmem: 168988 kB KReclaimable: 192936 kB Slab: 250520 kB SReclaimable: 192936 kB SUnreclaim: 57584 kB KernelStack: 11680 kB PageTables: 30800 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 4102308 kB Committed_AS: 7307340 kB VmallocTotal: 259653632 kB VmallocUsed: 20068 kB VmallocChunk: 0 kB Percpu: 736 kB CmaTotal: 327680 kB CmaFree: 288920 kB

In the terminal the formatting is better, all the values are right aligned (with the exception of VmallocTotal).

sberl commented 1 year ago

Okay. Think it's fixed. Can you please try out https://github.com/sberl/signalk-rpi-monitor/blob/comma-as-decimal/index.js and tell me if you get correct values for memory and CPUutilization

JonyIvy commented 1 year ago

Great, values are shown now. A bit strange though that the CPU load from the plugin shows about 5% higher than in top.