Ruby Script For Checking Memory Usage in domU From dom0 in Xen

Posted by Tres Sun, 20 Apr 2008 00:36:00 GMT

Here’s a little ruby hackery to do convert the output we got here into something like this:

MB total: 2432.0
MB used: 479.6953125
MB free: 1952.3046875

#!/usr/bin/env ruby

require 'optparse'

options = {}
outprint = {}
ot = String
opts = OptionParser.new do |opts|
        opts.on("-p X", "--path X", String, "path to partition for host") do |path|
                options[:path] = path
        end
end

opts.parse!(ARGV)

output = `dumpe2fs -h #{options[:path]}`
output.squeeze!(" ")
output.each do | line |
        line.grep(/Block count:/) { | total | outprint[:total_label] ,outprint[:total_data] = total.chomp.split(/\s*\:\s*/) }
        line.grep( /Free blocks:/) { | free | outprint[:free_label], outprint[:free_data] = free.chomp.split(/\s*\:\s*/) }
        line.grep(/Block size:/) { | size | outprint[:block_size_label], outprint[:block_size_data] = size.chomp.split(/\s*\:\s*/) }
        line.grep(/Reserved block count:/) { | reserved | outprint[:reserved_label], outprint[:reserved_data] = reserved.chomp.split(/\s*\:\s*/) }

end

mb_available = ( outprint[:block_size_data].to_f / 1048576 * outprint[:total_data].to_f )
mb_free = ( outprint[:block_size_data].to_f / 1048576 * outprint[:free_data].to_f )
mb_used = ( mb_available.to_f - mb_free.to_f )
puts "MB total: #{mb_available}"
puts "MB used: #{mb_used}"
puts "MB free: #{mb_free}"

The ruby script takes a single argument, the path to the device that is going to be looked at. It can be passed with either a -p or –path.

Posted in , , , ,  | Tags , , , , ,

Finding Disk Usage in DomU from Dom0 in Xen

Posted by Tres Sat, 12 Apr 2008 11:48:00 GMT

If you’re trying to monitor disk usage in a Xen domU and are using ext3fs formatted filesystems on LVM partitions, you can use dumpe2fs -h to get an idea of the current disk usage in domU from dom0.

[tres blas.phemo.us ~]$ sudo dumpe2fs -h /dev/vol00/xen_root_img 
dumpe2fs 1.39 (29-May-2006)
Filesystem volume name: 
Last mounted on: 
Filesystem UUID: d18fab79-7123-4289-bd28-222ec8739874
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal resize_inode dir_index filetype needs_recovery sparse_super large_file
Default mount options: (none)
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 311296
Block count: 622592
Reserved block count: 31129
Free blocks: 336965
Free inodes: 256927
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 151
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 16384
Inode blocks per group: 512
Filesystem created: Tue Feb 5 18:57:47 2008
Last mount time: Fri Feb 15 14:42:15 2008
Last write time: Fri Feb 15 14:42:15 2008
Mount count: 6
Maximum mount count: 25
Last checked: Tue Feb 5 19:01:06 2008
Check interval: 15552000 (6 months)
Next check after: Sun Aug 3 20:01:06 2008
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 128
Journal inode: 8
First orphan inode: 32775
Default directory hash: tea
Directory Hash Seed: d3f9829f-e127-427b-be56-4e840a139ccf
Journal backup: inode blocks
Journal size: 64M

So amongst all of the output, there are three lines that provide the magic: Block count:, Block size: and Free blocks:.

It’s easy enough to grab the three lines and then process them however you need to. This is a link to a ruby script that will check domU disk usage from dom0

Posted in , ,  | Tags , , ,

Logging In to Xen Console After Receiving "xenconsole: Could not open tty" Error

Posted by Tres Sun, 23 Dec 2007 10:55:00 GMT

So you try and log in to a domU and xen says it can’t open a tty?

[tres@calliope ~]$ sudo xm console xen-domu.vm
xenconsole: Could not open tty `/dev/pts/15': No such file or directory

This error normally happens when xenconsoled is no longer running. You can quickly verify by looking for the xenconsoled process:

[tres@calliope ~]$ ps auxwww | grep xenconsoled
[tres@calliope ~]$

If you don’t find it, just run

/etc/init.d/xend start

Posted in , ,  | Tags , ,

Setting Up Xen Console Access

Posted by Tres Sat, 20 Oct 2007 12:55:00 GMT

Being able to drop in to your domU via console requires that a terminal be set up in /etc/inittab.

A basic terminal configuration that will allow you to have access to domU is just to set up bash as the terminal ‘device.’

Just add the following to your /etc/inittab to get basic access:

1:2345:respawn:/bin/sh

However, you should beware when using a shell directly; you will lose the ability to send job control keystrokes, such as ctrl + c because there is not controlling terminal for the shell.

Another alternative is to use the xvc0 device instead. This not only gives you all the functionality you expect from a normal terminal based shell, but also has the additional benefit of providing your domU some security. By using xvc0 anyone wanting to use the console to gain access to your system must give valid credentials before they have access to the system (just like logging in locally via console).

Posted in , ,  | Tags , , , , ,

Gentoo Xen DomU Problems with /proc

Posted by Tres Mon, 15 Oct 2007 13:40:00 GMT

Setting up a Gentoo Xen DomU is pretty straight-forward. The only gotcha that you may run into is when Gentoo tries to mount /proc and dies with a message that includes:

The "mount" command failed with error: proc already mounted

Fixing this is just a matter of commenting out the section of /sbin/rc that attempts to mount /proc begining at around line 217 like this:

#       check_statedir /proc
#
#       ebegin "Mounting proc at /proc"
#       if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
#               mntcmd=$(get_mount_fstab /proc)
#       else
#               unset mntcmd
#       fi
#       try mount -n ${mntcmd:--t proc proc /proc -o noexec,nosuid,nodev}
#       eend $?

You’ll also need to comment the section attempting to mount /sys as well, or the next time you boot, you’ll get the same error with a different mount point failing.

#       if [ "$(get_KV)" -ge "$(KV_to_int '2.6.0')" ] ; then
#               if [[ -d /sys ]] ; then
#                       ebegin "Mounting sysfs at /sys"
#                       if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
#                               mntcmd=$(get_mount_fstab /sys)
#                       else
#                               unset mntcmd
#                       fi
#                       try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}
#                       eend $?
#               else
#                       ewarn "No /sys to mount sysfs needed in 2.6 and later kernels!"
#               fi
#       fi

Posted in , ,  | Tags , ,