[Nagiosplug-devel] check_maxchannels for perl framework
Stanley Hopcroft
Stanley.Hopcroft at IPAustralia.Gov.AU
Tue Mar 30 15:22:04 CEST 2004
Dear Sir,
I am writing to thank you for your 'small patches' and compliment you on
your prolificity.
Well done !
Please would you consider a group posting of
. your rationale (small dot points for me please) for this approach
- eg facilitate plugin integration in GUI config manager ?
. the performance impact of the new framework (/usr/bin/time repeatd a
few times [vi] of the original plugin and that in the framework)
. how it performs under ePN - can't imagine it's a problem and I will
probably try this.
I like the 'opt in' approach to option checking; that alone should make
a plugin authors lot a much easier one.
Yours sincerely.
--
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------
'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'
from Meditation 17, J Donne.
-------------- next part --------------
#!/usr/bin/perl -w
use strict ;
#
#
# dotime
#
# L Wall, "Programming Perl 1st ed" p 331
#
# usage dotime repeat command
# updated for P 5 by S Hopcroft
die "Usage: dotime <repeat> <command>\n" if @ARGV < 2 ;
my $repeat = shift(@ARGV) ;
die "Invalid repeat: $repeat, stopped"
unless (($repeat > 0) && ($repeat < 999)) ;
use vars qw($arg) ;
my $times = ($repeat == 1 ? "once" : "$repeat times") ;
print qq/Running @ARGV $times\n/ ;
$| = 1 ;
my %run_time = ( real => { total => 0, list => [] },
user => { total => 0, list => [] },
sys => { total => 0, list => [] }
) ;
for my $pass (1 .. $repeat) {
print "$pass " ;
open (TIMES, "/usr/bin/time @ARGV 2>&1 |")
|| die "Can't run /usr/bin/time @ARGV 2>&1, stopped" ;
while (<TIMES>) {
my %t ;
if ( @t{ qw(real user sys) } = /^\s*(\S+) real\s*(\S+) user\s*(\S+) sys/ ) {
foreach my $time ( keys %run_time ) {
$run_time{$time}{total} += $t{$time} ;
push @{ $run_time{$time}{list} }, $t{$time} ;
}
}
}
close (TIMES) ;
}
print "done\n" ;
my $fields_per_line = 15 ;
my ($fields, $values, $avg, $form) ;
$form = "format STDOUT =\n" ;
if ( $repeat <= $fields_per_line) {
$fields = '@<<<<@>>>>>>' . '@>>>>>>>>' x $repeat ;
$values = '$arg,$avg ' . ',shift @_' x $repeat ;
$form .=<<EOF ;
$fields
$values
.
EOF
} else {
# XXXX
# The values must follow the picture lines.
# So they must be wrapped also (otherwise a SEGV from the write statement).
# XXXX
my $data_fields = $fields_per_line - 2 ;
# Only $fields_per_line - 2 datum are displayed on each line of output
my $spaces = ' ' x 12 ;
# the multiple of ' ' is the number of chars used by the $arg and $avg fields in the first line
# PLUS the number 2 (for the '@' field markers) so that the fields line up for debugging.
my $fields = '@<<<<@>>>>>>' . '@>>>>>>>>' x $data_fields ;
my $values = '$arg,$avg ' . ',shift @_' x $data_fields ;
$form .=<<EOF ;
$fields
$values
EOF
my $line_pics = $spaces . '@>>>>>>>>' x $data_fields ;
my $line_vals = $spaces . ',shift @_' x $data_fields ;
my $lines_remaining = int( ($repeat - $data_fields)/$data_fields ) ;
$form .=<<EOF x $lines_remaining ;
$line_pics
$line_vals
EOF
my $fields_remaining = ($repeat - $data_fields) % $data_fields ;
$fields = ( $fields_remaining ? $spaces . '@>>>>>>>>' x $fields_remaining : "\n" ) ;
$values = ( $fields_remaining ? $spaces . ',shift @_' x $fields_remaining : "\n" ) ;
$form .=<<EOF ;
$fields
$values
.
EOF
}
# XXXX
$arg = ' ' ;
# $arg __cannot__ be a lexical or its value is not displayed.
# XXXX
eval $form ;
sub write {
$avg = shift ;
write ;
}
&write('Avg', 1 .. $repeat) ;
&write(split(' ', ' ------' x ($repeat + 1))) ;
foreach $arg ( qw(real user sys) ) {
&write( sprintf("%6.3f", $run_time{$arg}{total}/$repeat),
@{ $run_time{$arg}{list} }
) ;
}
More information about the Devel
mailing list