WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-users

Re: [Xen-users] Monitoring domU resource usage

To: Andy Smith <andy@xxxxxxxxxxxxxx>
Subject: Re: [Xen-users] Monitoring domU resource usage
From: Tom Brown <tbrown@xxxxxxxxxxxxx>
Date: Wed, 8 Jun 2005 10:17:40 -0700 (PDT)
Cc: Xen-users <Xen-users@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Wed, 08 Jun 2005 17:17:14 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <20050608160948.GB750@xxxxxxxxxxxxxx>
List-help: <mailto:xen-users-request@lists.xensource.com?subject=help>
List-id: Xen user discussion <xen-users.lists.xensource.com>
List-post: <mailto:xen-users@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-users-bounces@xxxxxxxxxxxxxxxxxxx
On Wed, 8 Jun 2005, Andy Smith wrote:

> Using 2.0-testing, what methods are people using to monitor
> individual domU CPU usage?
>
> Obviously I can run an snmpd in each domU and see how busy the CPU
> is, but that could be tampered with from inside the domU, and as the
> domU doesn't know it doesn't have the whole cpu needs some
> interpretation.
>
> I can see CPU time used in "xm list" but that looks like rather a
> blunt tool - would I have to do something like this for example:

AFAIK, from what you describe you don't have much choice, you are going to
have to watch from _both_ the inside and the outside. I guess you might be
able to guess which domU is requesting CPU if the total CPU on the box
goes to 100%.

I have a script that polls xm list ever 60 seconds and logs the results.
>From this I can get a feeling for what % of the CPU is being consumed and
which dom is using it...

e.g.

[root@xen1 ~]# more ~tbrown/uptime.log.xen
Wed Jun  8 00:00:01 PDT 2005
  Domain-0  2.48% cpu usage  102461.38 sec over 47.91 days
domain-dns 16.91% cpu usage  501043.99 sec over 34.30 days
   mailman  0.70% cpu usage  6938.28 sec over 11.53 days
        mx 27.56% cpu usage  605861.02 sec over 25.44 days

  1   7   1  20  68
  1  11   2  27  55
  3  96   0  35 -36
  2  48   0  26  21
  1   8   0  32  56
  1   5   0  31  60
  2   6   0  38  51
  1  12   0  21  64
  2  13   0  34  49
  2  21   0  36  37
  1   8   0  31  57
  2  14   0  34  48


Where the columns are the doms in the order described in the header... and
the last column being idle time.

hhmm, the script is only 67 lines... I will include it...
The polling frequency and number of samples to take are
commandline parameters, I run it hourly as "script 60 59" in my
crontab.

here goes:

#!/usr/bin/perl
#
# script to dump CPU stats for VMs
#
# vim:ai

use strict;

my $interval = shift || 5;
my $num_samples = shift || 0;

my $uptime = `cat /proc/uptime`;
$uptime =~ s/ .*$//g; # trim from first space, should leave us uptime in
secs

my $XM="/usr/sbin/xm";


my $loop = 0;
my $lasttimestamp = 0;
my %lastcpu = ();
while ( ++$loop ) { # loop forever
   my $buf = '';
   my $count = 0;
   my $dat = `$XM list -l`
      or die "no output from $XM list ?? maybe it isn't in your path?";
   my $datatimestamp = time();
   $dat =~ tr/\(\)/{}/;  # for readability of regex below.
   my $totcpu = 0;

   while ( my($dom,$rest) = ($dat =~ m/^(.*?\n})(.*)$/gs ) ) {
      my ($domcpu) = ($dom =~ m/{cpu_time\s([\d\.]+)}/)
         or die "couldn't extract cpu_time from $dom on dom $count\n";
      my ($domup) = $uptime;
      if ($count > 0 ) {
         ($domup) = ($dom =~ m/{up_time\s([\d\.]+)}/)
            or die "couldn't extract up_time from $dom on dom $count\n";
      }
      my $domname = "dom-$count";
      {
         my ($tmp) = ($dom =~ m/{name\s(.+)}/);
         $domname = $tmp if ($tmp);
      }

      if ($loop <= 1) {
         $buf .= sprintf "%10s %5.2f%% cpu usage  %.2f sec over %.2f days\n",
            $domname, 100 * $domcpu/$domup, $domcpu, $domup/24/3600;
      } else {
         my $cpu = $domcpu-$lastcpu{$count};
         $totcpu += $cpu;
         $buf .= sprintf "%3d ",
            100 * $cpu/$interval;
      }
      $lastcpu{$count} = $domcpu;
      $dat = $rest;
      $count++;
      die "count exceeded" if ($count > 100);
   }
   my $period = ($datatimestamp - $lasttimestamp);
   if ($loop > 1) {  # add on idle cpu
      $buf .= sprintf "%3d", 100 * ($interval - $totcpu)/$period;
   }
   $lasttimestamp = $datatimestamp;
   print "$buf\n";
   exit if ($num_samples && $loop > $num_samples);
   sleep $interval;
}


_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users

<Prev in Thread] Current Thread [Next in Thread>