nuber-io / nuber

Virtualization management software
https://www.nuber.io
GNU Affero General Public License v3.0
29 stars 5 forks source link

CPU usage in % display? #3

Closed StormYudi closed 3 years ago

StormYudi commented 3 years ago

Hi, I love this project and thank you for your hard work! But can you add "CPU Usage %" in dashboard ? I know there is no such API in lxd, but I think maybe we can calculate the percent of CPU, such as :

CPU % = ( ( cpu seconds now - cpu seconds before ) / (duration time cores of the container)) 100

So we can know where the noise comes from :D

jamielsharief commented 3 years ago

Just started to write a concept, but i am not sure it is correct, since even after installing and running stress CPU usage is really low.

{ "cores": 2, "before": 760732242, "now": 760761117, "usage": 0.00144375 }

image

StormYudi commented 3 years ago

Eh, I am sorry, but could you please try change "cpu seconds" to "cpu nano seconds" ?

jamielsharief commented 3 years ago

The usage is already in nanoseconds according to the maintainer.

https://discuss.linuxcontainers.org/t/lxd-api-units-for-memory-disk-and-cpu-usage/6643/2 https://discuss.linuxcontainers.org/t/lxd-api-units-for-memory-disk-and-cpu-usage/6643/4

jamielsharief commented 3 years ago

Okay, using stress -c 8 seems to show up now, not sure how reliable it is and if i should be expecting a 100% because it only has 2 vCPU limit.

image

StormYudi commented 3 years ago

760732242ns = 0.7607322s, 760761117ns=0.7607611s, You run stress test for one second, but it just use 0.00004s of CPU? I think there must be something wrong.....

jamielsharief commented 3 years ago

Okay it seems to be working

I run the following command

stress -c 1 -v --timeout 30s

{
    "data": {
        "before": 333865385548,
        "now": 334907737458,
        "cores": 1,
        "diff": 1042351910,
        "percent": 104.235191
    }
}

With 2 x vCPUs

{
    "data": {
        "before": 64644678797,
        "now": 65685198546,
        "cores": 2,
        "diff": 1040519749,
        "percent": 52.02598745
    }
}

3x vCPUs

{
    "data": {
        "before": 93983394514,
        "now": 95027642800,
        "cores": 3,
        "diff": 1044248286,
        "percent": 34.8082762
    }
}

4x vCPUs

{
    "data": {
        "before": 124745298267,
        "now": 125789750428,
        "cores": 4,
        "diff": 1044452161,
        "percent": 26.111304025
    }
}

top always reports 50% CPU usage once there is more than 1 core.