Script to monitor realtime CPU & Bandwidth usage in xen live migration

1

I need to write a script (bash or python or ??) to perform live migration of a VM in xen, and to simultaneously log and extract the CPU & bandwidth usage of the Domain-0 AND write the output into a text file in a well-formed format.

What I did so far:
I currently use this code to log the CPU usage of the 'Domain-0':

xentop -d1 -bi500 | awk '$1 == "Domain-0" { print $4 }'

It reads the cpu usage from xentop command every second and prints it in bash. I couldn't find a way to write the output into a text file.

And to simultaneously migrate the VM and monitor the cpu usage I do this:

xentop -d1 -bi500 | awk '$1 == "Domain-0" { print $4 }' & xl migrate vm1 destination-host --live --debug

So that both commands run possibly at the same time and when I see that migrate command finishes I copy the printed cpu usages from when the migrate command starts till it finishes and paste them in a text file. this is boring and not accurate!!

So I need a way to script everything in a wise way so that whenever I execute it, it requests the name of the VM and the destination ip or hostname, then it triggers the migration command and logs the CPU & bandwidth at the same time, and time-stamps every output so I could accurately determine what happens during the live migration process.
Something like this:

Migration Started
     CPU(%)      Bandwidth(MB/s)     Time
     26          14.8                14:31:26
     32.5        13.2                14:31:27
                     ...
                     ...
                     ...
     10          0.5                 14:32:54
Migration Finished

I also need a piece of code to determine the realtime bandwidth usage of Domain-0.

Ali

Posted 2015-07-04T14:15:20.713

Reputation: 111

This has more information: timeout 5s rrd2csv -n – dashesy – 2017-02-02T01:24:15.307

Answers

0

First, thank you very very much for this command because it solved to me a problem.

Answering your question, you can make the iteration only 1, so the bash code will cancel in one iteration and then you can get the output using ">file.txt". And you can put all this code in a loop with 500 iterations or what you want.

geniant

Posted 2015-07-04T14:15:20.713

Reputation: 1