independent_wallclock in Xen 4

I was asked to set up clock synchronization for a Xen VM, running on top of Xen 4.0, which in turn was running on top of a Debian Squeeze. As you may know, NTP on VMs just sucks, so I was looking for Xen 3.0's independent_wallclock setting, and have domU's clock follow dom0's.

With my surprise, /proc/sys/xen/independent_wallclock wasn't there anymore.

With some surprise (but not as much), my searches in Google returned just crap.

As it often happens, IRC came to the rescue. Or, well: no rescue, but at least I was provided with a reason:

(15:51:10) The topic for ##xen is: Xen 4.0 http://www.xen.org/downloads | XCP http://blog.xen.org/index.php/2010/11/24/the-xen-cloud-platform-xcp-1-0-beta-is-available-from-xen-org/ | Wiki: http://wiki.xen.org/ | Solaris: http://www.opensolaris.org/os/community/xen/ | Logs: http://zentific.com/irclogs | Management: check out #zentific
(15:54:48) bronto@freenode: hello! It's maybe an FAQ, but I couldn't find an answer anywhere. Xen 4.0 doesn't have /proc/sys/xen/independent_wallclock (at least, not in Debian Squeeze Linux). Is there any equivalent?
(15:55:14) bronto@freenode: I would like domUs to follow dom0's clock, and sync dom0 using NTP.
(15:55:42) pasik: bronto: it depends on the kernel
(15:55:47) pasik: bronto: pvops kernels don't have it
(15:55:57) pasik: bronto: old xenlinux kernels do have it
(15:56:33) bronto@freenode: pasik: thanks. hmmm… so, the solution is: use a different kernel?
(15:56:40) pasik: bronto: or ntp
(15:56:55) bronto@freenode: pasik: NTP on domU's? Uh, that just sucks…
(15:58:57) pasik: bronto: pvops (upstream) kernels don't have independent_wallclock because there was some problems with it, it wasn't thought to be accepted to upstream Linux
(15:59:03) pasik: bronto: I can't remember the details now
(15:59:27) bronto@freenode: pasik: ouch… 😦
(15:59:41) bronto@freenode: pasik: this is damn bad
(16:00:31) bronto@freenode: pasik: OK. I'll fall back to ntp, and hope it will work

New module on CPAN: Log::Stderr

I published my fourth module on CPAN today: Log::Stderr. As the name says, it will write timestamped log messages to STDERR.

Like the other three I published back in 2004, it's not rocket science. But it is something that I was using to help me debug small scripts, and I found it very convenient. So I am publishing it in the hope that it will be useful for someone else. Of course this module won't be much useful if you have more than basic needs, but it's not a problem: there are so many good modules in the Log:: hierarchy! And if you are in doubt about which one to use, well, visit "the Monastery" and ask the monks 😉

Enjoy!

Adding bulks of SNMP hosts to cacti, updated

I did some changes to the makefile I published last month. It would be too much to completely rewrite the blog post to adapt for the changes, so I am just publishing the update here, and you can do the diff yourself.

There is still a lot of factorization left to do, I am leaving it to when I'll have more time. If, in the meanwhile, you come up with a better version, please leave a comment here.

I still have problems with LVS metrics, in particular: "LVS traffic in" is not getting any data. If you can spot the mistake and tell me, that would be much appreciated.

Have fun! … Continue reading

Quickly graphing RRD data

Still fiddling with RRD, and I'm about at the end of the tunnel 🙂 I finally collected a significant amount of data, and I have scripts to aggregate different sources. What I was missing was a quick way to generate graphs, so that I could visually check if my aggregated data "looks" OK.

As usual, the syntax of rrdtool graph is quite verbose and cryptic, not exactly what you hope when all you need is a quick one-shot graph of some RRD files.

As always, Perl comes to the rescue, this time with RRD::Simple. RRD::Simple is by default able to generate nice graphs with pre-loaded color schemes –if you suck at choosing colors like me, this is a really appreciable feature. It has a set of pre-defined graphs that it can generate, as well, but since it accepts native RRD options (beside its own set), it's actually easy to bend it at your need, and generating a graph just needs a one-liner:

perl -MRRD::Simple -e 'RRD::Simple->graph("aggr_root_storage.rrd", destination => "/tmp", sources => [ qw{perc_used worst_perc_free} ], width => 1024, height => 768, start => 1288566000, end => 1291158000, periods => [ "daily" ] )'  

Or, reindented:

perl -MRRD::Simple -e 
  'RRD::Simple->graph("aggr_root_storage.rrd", 
    destination => "/tmp", 
    sources => [ qw{perc_used worst_perc_free} ], 
    width => 1024, height => 768, 
    start => 1288566000, end => 1291158000, 
    periods => [ "daily" ] )'

The periods options, in this case, has no purpose but to generate only one graph (otherwise you would get many graphs, all equal; why? go and find out yourself, if you really care 😉

And what about plotting a collection of RRDs? It could be something like:

$ for FILE in aggr*.rrd ; do export FILE ; perl -MRRD::Simple -e 'RRD::Simple->graph($ENV{FILE}, destination => "/tmp", width => 1024, height => 768, start => 1288566000, end => 1291158000, periods => [ "daily" ] )' ; done   

or, clearer:

$ for FILE in aggr*.rrd ; 
do 
  export FILE ; 
  perl -MRRD::Simple -e 
    'RRD::Simple->graph($ENV{FILE}, 
      destination => "/tmp", 
      width => 1024, height => 768, 
      start => 1288566000, end => 1291158000, 
      periods => [ "daily" ] )' ; 
done

THINK!

Reading in one of the blogs I keep an eye on (I didn't say I read it thorougly all the time, I just keep an eye on it) I stumbled upon the acronym THINK. It refers to five qualities that what you write should always have, especially when you're communicating with other people.

Each time you are writing, or at least before you rush to the "Send" button in your MTA, you should consider if what you have just written is:

Thoughtful
Honest
Intelligent
Necessary
Kind

I admit I sometimes sin with T and N, and in the worst case with K 😦

A more general approach for AppConfig

In my previous post about AppConfig I suggested an approach in order to read configuration options from a file, and override them with command-line options. It turns out that it works pretty well in the most common case (that is: only scalar variables are involved), but works really bad when list variables come into play.

The problem lies in the command line parsing happening two times, so while scalar variables are overwritten with the same value they had at the first pass, the list variables add the specified value again. Probably, not what you want. The fix is actually trivial:

# Reading configuration
# The first AppConfig object, we'll throw it away. We'll use it
# just to discover if there is a config file that we should read
# first, and then override config file options on the command line
my $config_file ;
{
  my $c        = AppConfig->new($ACparms,@config_vars) ;
  my $args     = [ @ARGV ] ;

  $c->args($args) ;
  $config_file = $c->get("config") ;
}

my $c = AppConfig->new($ACparms,@config_vars) ;

if (defined $config_file) {
  $c->file($config_file) ;
}

$c->args() ;

So basically, we parse the command line the first time inside a bare block, and just to find out if the config option was specified; that option will tell us if we have to parse a configuration file. Once the bare block is over, the AppConfig object ceases to exist, so when we get to the command line again, we are starting from scratch: no duplicated list values any more 🙂

Useful command-line options in CUPS

I often have to go back to CUPS documentation. I don't use the command line tools nowadays, so I manage to forget the command line options from one time to another. That's enough to write a blog post about that, in order to have a short note to refer to 🙂

Printing in landscape mode is:
lpr -o landscape filename

How many sides?
lpr -o sides=one-sided filename is one sided
lpr -o sides=two-sided-short-edge filename is two sides, flipping along the short edge of the page
lpr -o sides=two-sided-long-edge filename is two sides, flipping along the long edge of the page

Printing N pages per page (n-up or number-up printing) is:
lpr -o number-up=N filename

Page fitting is:
lpr -o fit-to-page filename

Pretty-printing:
lpr -o prettyprint filename
This one is especially useful for those that use C/C++ but, unfortunately, of limited use for those who use Perl. XEmacs' prettyprinting is very good for that, by the way.

Print N copies:
lpr -#N filename

Using AppConfig in 10 minutes

This is a short HOWTO for the AppConfig module. It assumes some knowledge of how to use Perl modules.

What it is
AppConfig is a Perl module that allows you to manage a program’s configuration in a simple way, with both configuration files and command line options.

AppConfig configurations support scalar variables, arrays and hashes, which naturally translate into Perl variables.

Continue reading