Discussion:
[PVE-User] pvesh get current status and cpu value
Daniel Berteaud
2018-06-01 14:52:27 UTC
Permalink
Hi.


Writing some script to monitor my guests on a proxmox 5.2 cluster (3
nodes), I find something strange. When I ask the current status of a
guest, eg

pvesh get /nodes/pve1/qemu/109/status/current

I get most stats I want, except for CPU usage. I guess it should be the
value of cpu (cpus being the number of cores assigned to the VM, and cpu
the % used), but the value I get for cpu is always 0, no matter the
activity of the VM.

Am I missing something, or is this a bug ?


BTW, I'd have asked this on the forum, but I get "You have insufficient
privileges to post here"


Regards, Daniel
--
Logo FWS

*Daniel Berteaud*

FIREWALL-SERVICES SAS.
Société de Services en Logiciels Libres
Tel : 05 56 64 15 32 <tel:0556641532>
Matrix: @dani:fws.fr
/www.firewall-services.com/
René Jochum
2018-06-01 14:55:24 UTC
Permalink
Get it from "pvesh get /cluster/resources" :)

In Javascript i calc the cpu usage like this:

Math.round(this.getCpu() *100*10) /10; Kind regards, René
Hi. Writing some script to monitor my guests on a proxmox 5.2 cluster
(3 nodes), I find something strange. When I ask the current status of
a guest, eg pvesh get /nodes/pve1/qemu/109/status/current I get most
stats I want, except for CPU usage. I guess it should be the value of
cpu (cpus being the number of cores assigned to the VM, and cpu the %
used), but the value I get for cpu is always 0, no matter the activity
of the VM. Am I missing something, or is this a bug ? BTW, I'd have
asked this on the forum, but I get "You have insufficient privileges
to post here" Regards, Daniel
Daniel Berteaud
2018-06-01 15:08:27 UTC
Permalink
Post by René Jochum
Get it from "pvesh get /cluster/resources" :)
Indeed, here it has the correct value. Still, isn't that strange that on
/nodes/<node>/qemu/<vmid>/status/current we do not get the same value ?

Thanks,
Daniel
--
Logo FWS

*Daniel Berteaud*

FIREWALL-SERVICES SAS.
Société de Services en Logiciels Libres
Tel : 05 56 64 15 32 <tel:0556641532>
Matrix: @dani:fws.fr
/www.firewall-services.com/
René Jochum
2018-06-01 15:11:39 UTC
Permalink
Hi Daniel,

Its complicated why this is 0, in short cpu usage is a counter its hard
to calculate actual usage in % without history data.

/cluster/resources uses pvestatd which calculates that,
/nodes/{node}/(qemu|lxc)/status/current doesn't.

Np,

René
Post by Daniel Berteaud
Post by René Jochum
Get it from "pvesh get /cluster/resources" :)
Indeed, here it has the correct value. Still, isn't that strange that on
/nodes/<node>/qemu/<vmid>/status/current we do not get the same value ?
Thanks,
Daniel
Dietmar Maurer
2018-06-04 04:31:34 UTC
Permalink
Post by René Jochum
Its complicated why this is 0, in short cpu usage is a counter its hard
to calculate actual usage in % without history data.
/cluster/resources uses pvestatd which calculates that,
/nodes/{node}/(qemu|lxc)/status/current doesn't.
Yes, this is probably the best workaround. Please note that
pvesh is mostly a debugging tool. But we are working on a
full feature API client tool, which provides about the same
functionality, but queries the API daemon instead. This will
then compute such values correctly.
Daniel Berteaud
2018-06-04 08:48:24 UTC
Permalink
Post by Dietmar Maurer
Post by René Jochum
Its complicated why this is 0, in short cpu usage is a counter its hard
to calculate actual usage in % without history data.
/cluster/resources uses pvestatd which calculates that,
/nodes/{node}/(qemu|lxc)/status/current doesn't.
Yes, this is probably the best workaround.
And it's  what I'm doing now, which is working great. Thanks to both of you
Post by Dietmar Maurer
Please note that
pvesh is mostly a debugging tool.
Well, maybe it was designed as a debugging tool, but it perfectly fit my
needs. I needed JSON output of some elements, without having to deal
with authentication (especially without having to store cleartext
passwords somewhere)
Post by Dietmar Maurer
But we are working on a
full feature API client tool, which provides about the same
functionality, but queries the API daemon instead. This will
then compute such values correctly.
I'll check this tool when it's available :-)

++
--
Logo FWS

*Daniel Berteaud*

FIREWALL-SERVICES SAS.
Société de Services en Logiciels Libres
Tel : 05 56 64 15 32 <tel:0556641532>
Matrix: @dani:fws.fr
/www.firewall-services.com/
Thomas Lamprecht
2018-06-01 15:12:17 UTC
Permalink
Hi,
Post by Daniel Berteaud
Hi.
Writing some script to monitor my guests on a proxmox 5.2 cluster (3
nodes), I find something strange. When I ask the current status of a
guest, eg
pvesh get /nodes/pve1/qemu/109/status/current
I get most stats I want, except for CPU usage. I guess it should be the
value of cpu (cpus being the number of cores assigned to the VM, and cpu
the % used), but the value I get for cpu is always 0, no matter the
activity of the VM.
Am I missing something, or is this a bug ?
actually cpu should be set and represent what you expect,
I took a quick look at the code and did not see why it
shouldn't be set...
It's in the PVE::QemuServer::vmstatus method, but I got no time today to
investigate in this, sorry :)
Post by Daniel Berteaud
BTW, I'd have asked this on the forum, but I get "You have insufficient
privileges to post here"
regarding this: you run into our forums spam alert,
now you should be able to post :)

cheers,
Thomas
Daniel Berteaud
2018-06-01 15:28:32 UTC
Permalink
Post by Thomas Lamprecht
Hi,
Post by Daniel Berteaud
Am I missing something, or is this a bug ?
actually cpu should be set and represent what you expect,
I took a quick look at the code and did not see why it
shouldn't be set...
It's in the PVE::QemuServer::vmstatus method, but I got no time today to
investigate in this, sorry :)
Took a quick look, and it looks like it should be populated around line 2890

        if ($dtime > 1000) {
            my $dutime = $used -  $old->{used};

            $d->{cpu} = (($dutime/$dtime)* $cpucount) / $d->{cpus};
            $last_proc_pid_stat->{$pid} = {
                time => $ctime,
                used => $used,
                cpu => $d->{cpu},
            };

But my perl-foo will probably reach it's limit quickly ;-)
Will try to debug this if I can.
Post by Thomas Lamprecht
regarding this: you run into our forums spam alert,
now you should be able to post :)
Thanks, I can indeed now :-)
--
Logo FWS

*Daniel Berteaud*

FIREWALL-SERVICES SAS.
Société de Services en Logiciels Libres
Tel : 05 56 64 15 32 <tel:0556641532>
Matrix: @dani:fws.fr
/www.firewall-services.com/
Loading...