`ProcessCPUUsage` field values doesn't mean anything
Recently, I switched from the old version of this module to the new one and I noticed that the ProcessCPUUsage field was giving completely ununderstandable values and didn't seem to make sense compared to the others.
For example, here is the result I can get (it happens to me all the time and is not exceptional):
> PrintTable(serverstat.All())...
LogicalCPUs = 8
PhysicalCPUs = 8
ProcessCPUUsage = 40300 -- ???
ProcessMemoryUsage = 572.24609375
SystemAvailableMemory = 19969.983398438
SystemCPUUsage = 41.920177459717
SystemMemoryUsage = 49319.202148438
SystemTotalMemory = 70362.319335938
The same thing happens with the asynchronous function (but sometimes it returns 0 without any reason).
> serverstat.async.All(function(data) PrintTable(data) end)...
LogicalCPUs = 8
PhysicalCPUs = 8
ProcessCPUUsage = 0 -- ???
ProcessMemoryUsage = 573.2109375
SystemAvailableMemory = 20000.5234375
SystemCPUUsage = 100 -- Why not
SystemMemoryUsage = 49288.662109375
SystemTotalMemory = 70362.319335938
For information, my server is on a dedicated machine hosted by a game provider (so I don't have control of the machine to check the stats). AFAIK, the server is running under Debian 10 64-bit.
] version
Protocol version 24
Exe version 2021.06.09 (garrysmod)
Exe build: 14:56:57 Jul 12 2021 (8283) (4000)
GMod version 2021.07.12, branch: unknown
Linux 32bit Dedicated Server
And here is the script I use to get the information from the module.
-- From : https://github.com/WilliamVenner/gmsv_serverstat/
if not file.Exists("bin/gmsv_serverstat_*.dll", "LUA") then return end
require("serverstat")
concommand.Add("server-stats", function(ply)
local data = serverstat.All()
local phrase = "CPU Usage : %s (%s/%s)\nMemory Usage : %s (%s)"
phrase = string.format(phrase,
math.Round(data.ProcessCPUUsage, 2) .. "%",
data.LogicalCPUs, data.PhysicalCPUs,
string.NiceSize(data.ProcessMemoryUsage * 10 ^ 6),
string.NiceSize(data.SystemTotalMemory * 10 ^ 6)
)
Raven.Server.SendChatMessage(ply, color_red, phrase)
end)
Extract from the docs for the upstream function
Returns the total CPU usage (in %). Notice that it might be bigger than 100 if run on a multicore machine.
If you want a value between 0% and 100%, divide the returned value by the number of CPU processors.
Warning: If you want accurate CPU usage number, better leave a bit of time between two calls of this method (200 ms for example).
This is what I do:
https://github.com/WilliamVenner/gmsv_serverstat/blob/4b42cdefb58f252248925ebfc17861aecafa677d/src/sysinfo.rs#L105
I believe this is sound. Can you check if you can reproduce this on Windows?
On Windows (and on Windows Server with a dedicated server), it seems these values are perfectly normal.
] lua_run PrintTable(serverstat.All())
> PrintTable(serverstat.All())...
LogicalCPUs = 8
PhysicalCPUs = 4
ProcessCPUUsage = 6.8244895935059
ProcessMemoryUsage = 634.419921875
SystemAvailableMemory = 7734.50390625
SystemCPUUsage = 16.620286941528
SystemMemoryUsage = 8981.4033203125
SystemTotalMemory = 16715.907226563
] lua_run serverstat.async.All(function(data) PrintTable(data) end)
> serverstat.async.All(function(data) PrintTable(data) end)...
LogicalCPUs = 8
PhysicalCPUs = 4
ProcessCPUUsage = 9.4401035308838
ProcessMemoryUsage = 635.7470703125
SystemAvailableMemory = 7742.8876953125
SystemCPUUsage = 11.839296340942
SystemMemoryUsage = 8973.01953125
SystemTotalMemory = 16715.907226563
But sometimes the SystemCPUUsage field returns 0 even if it has been previously called. I also tested this on another dedicated server but this time under CentOS 8 and I experience exactly the same problem described above.
@FlorianLeChat Can you test with v0.2.4?
lua_run serverstat.async.All(function(data) PrintTable(data) end)
> serverstat.async.All(function(data) PrintTable(data) end)...
LogicalCPUs = 1
PhysicalCPUs = 1
ProcessCPUUsage = 9100
ProcessMemoryUsage = 548.36328125
SystemAvailableMemory = 1802.69921875
SystemCPUUsage = 5.363748550415
SystemMemoryUsage = 1448.689453125
SystemTotalMemory = 3727.6279296875
I still get the problem unfortunately. The server is a VPS with 1 vCore and running CentOS 8. On Windows (and Windows Server), everything works perfectly.
@FlorianLeChat Looks like sysinfo may have made some fixes since, please give v0.2.5 a try.
The problem is still there, unfortunately.
lua_run serverstat.async.All(function(data) PrintTable(data) end)
> serverstat.async.All(function(data) PrintTable(data) end)...
LogicalCPUs = 2
PhysicalCPUs = 2
ProcessCPUUsage = 0
ProcessMemoryUsage = 925.6171875
SystemAvailableMemory = 1345.5234375
SystemCPUUsage = 4.6325511932373
SystemMemoryUsage = 2071.0537109375
SystemTotalMemory = 3728.015625
lua_run serverstat.async.All(function(data) PrintTable(data) end)
> serverstat.async.All(function(data) PrintTable(data) end)...
LogicalCPUs = 2
PhysicalCPUs = 2
ProcessCPUUsage = 100
ProcessMemoryUsage = 925.625
SystemAvailableMemory = 1345.3671875
SystemCPUUsage = 5.5462183952332
SystemMemoryUsage = 2071.2099609375
SystemTotalMemory = 3728.015625
Protocol version 24
Exe version 2021.06.09 (garrysmod)
Exe build: 14:56:57 Jul 12 2021 (8283) (4000)
GMod version 2021.07.12, branch: unknown
Linux 32bit Dedicated Server
(Always under CentOS 8)
Is the issue isolated to only CentOS? Do you know if it happens on other distros?
This is what I also said to myself when I wrote my answer just before, I have a feeling that CentOS might be the problem. I'm very tempted to install Debian and/or Ubuntu Server on a virtual machine tomorrow to test that.
If we can only reproduce this on CentOS, I can let the maintainer of sysinfo know and he can implement a fix.

I just did the test under Debian 11/Ubuntu 21.10 and I get the same problem (even when switching to the 64 bits version of the dedicated server).
This is just weird. My Ubuntu 16 is fine:

This issue is really confusing 😕
For more information, the tests I did today were done under VMWare 16 with the latest OS images and I installed a fresh new Garry's Mod server using LinuxGSM.
Ok, mine's under WSL. I doubt LinuxGSM could be doing that.