<div dir="ltr"><div><div><div>Actually my setup is like this:<br><br></div>I have one controller host that do this migration between other two nodes say A and B. Now where should this virDomainGetJobStats method should be invoked from ?<br> <br></div>If at present VM is migrated from A to B then should B call this method?<br><br></div>It's not clear.<br><br><br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">"CODENAME FREAK -47"</div></div></div>
<br><div class="gmail_quote">On Tue, Jan 10, 2017 at 8:48 PM, Jiri Denemark <span dir="ltr"><<a href="mailto:jdenemar@redhat.com" target="_blank">jdenemar@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Please, do not post to several libvirt lists at once.<br>
<span class=""><br>
> I am writing a code using libvirt API to migrate VM between two physical<br>
</span>> hosts *(QEMU/KVM) , *say some *n *number of times.<br>
><br>
> *1)* I am using right now* virDomainPtr virDomainMigrate (.......) *and to<br>
<span class="">> calculate the total migration time I am using something like this:<br>
><br>
</span>> *clock_gettime(CLOCK_<wbr>MONOTONIC_RAW,&begin);  *<br>
>  *migrate*(domainToMigrate,<wbr>nodeToMigrate);<br>
><br>
> *clock_gettime(CLOCK_<wbr>MONOTONIC_RAW,&end);*<br>
><br>
> *Total Migration Time = end.tv_sec-begin.tv_sec*<br>
<span class="">><br>
> Is this correct way to calculate total migration time. And is there some<br>
> way to calculate the downtime (not how to set it)?<br>
<br>
</span>Well, just call virDomainGetJobStats and you will get both total time<br>
and downtime and many more.<br>
<br>
> virDomainGetJobStats<br>
> <<a href="http://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobStats" rel="noreferrer" target="_blank">http://libvirt.org/html/<wbr>libvirt-libvirt-domain.html#<wbr>virDomainGetJobStats</a>><br>
<br>
Yes, this is the right API to get all the statistics you want. It<br>
returns a list of (key, type, value) entires in params. The keys are<br>
VIR_DOMAIN_JOB_* (see<br>
<a href="http://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_JOB_AUTO_CONVERGE_THROTTLE" rel="noreferrer" target="_blank">http://libvirt.org/html/<wbr>libvirt-libvirt-domain.html#<wbr>VIR_DOMAIN_JOB_AUTO_CONVERGE_<wbr>THROTTLE</a><br>
and a lot of other VIR_DOMAIN_JOB_* macros following this one for<br>
details). You can look at<br>
<a href="http://libvirt.org/git/?p=libvirt.git;a=blob;f=tools/virsh-domain.c;h=93587e8bc7c79cbb66b6ee107472dfec5f320dab;hb=HEAD" rel="noreferrer" target="_blank">http://libvirt.org/git/?p=<wbr>libvirt.git;a=blob;f=tools/<wbr>virsh-domain.c;h=<wbr>93587e8bc7c79cbb66b6ee107472df<wbr>ec5f320dab;hb=HEAD</a><br>
<br>
In short, just call<br>
<br>
    virTypedParamsGetULLong(<wbr>params, nparams, VIR_DOMAIN_JOB_DOWNTIME,<br>
                            &value)<br>
<br>
to fetch downtime from params into value if it was present there (check<br>
return value of the API). The exact API to call is different for each<br>
type, although all migration statistics are unsigned long long so this<br>
one is all you need.<br>
<br>
BTW, you can call virDomainGetJobStats anytime while migration is<br>
running to monitor its progress. To check statistics of a completed<br>
migration it's easier to just register a callback for<br>
VIR_DOMAIN_EVENT_ID_JOB_<wbr>COMPLETED event. See<br>
<a href="http://libvirt.org/git/?p=libvirt.git;a=blob;f=examples/object-events/event-test.c;h=55c004f93f40de628ae76221bb8ef9a13b2acb3d;hb=HEAD#l940" rel="noreferrer" target="_blank">http://libvirt.org/git/?p=<wbr>libvirt.git;a=blob;f=examples/<wbr>object-events/event-test.c;h=<wbr>55c004f93f40de628ae76221bb8ef9<wbr>a13b2acb3d;hb=HEAD#l940</a><br>
for an example.<br>
<br>
Jirka<br>
</blockquote></div><br></div>