| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | # $Id$ | ||
| 4 | # $LastChangedDate$ | ||
| 5 | # $Rev$ | ||
| 6 | |||
| 7 | use lib qw(./lib ../lib); | ||
| 8 | use Nagios::StatusLog; | ||
| 9 | use Benchmark ':hireswallclock'; | ||
| 10 | use Getopt::Std; | ||
| 11 | use Data::Dumper; | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | statusdat_demo.pl - test the StatusLog module | ||
| 16 | |||
| 17 | =head1 USAGE | ||
| 18 | |||
| 19 | perl statusdat_demo.pl -l /var/opt/nagios/status.dat | ||
| 20 | |||
| 21 | =head1 NOTES | ||
| 22 | |||
| 23 | Please send the benchmark outputs to duncs@cpan.org so I can see how the | ||
| 24 | performance is on boxes and configs other than my own. | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | our $opt_l; | ||
| 29 | getopt('l:'); | ||
| 30 | die "Must specify location of Nagios status log with -l option." | ||
| 31 | if ( !$opt_l ); | ||
| 32 | |||
| 33 | my $bench_begin = Benchmark->new; | ||
| 34 | my $log = Nagios::StatusLog->new( Filename => $opt_l, Version => 2.0 ); | ||
| 35 | |||
| 36 | my $bench_postparse = Benchmark->new; | ||
| 37 | |||
| 38 | #print Dumper( $log ); | ||
| 39 | |||
| 40 | foreach my $host ( $log->list_hosts ) { | ||
| 41 | my $obj = $log->host($host); | ||
| 42 | printf "Host: %s Last Update: %d\n", $obj->host_name, $obj->last_update; | ||
| 43 | |||
| 44 | } | ||
| 45 | |||
| 46 | my $prog = $log->program; | ||
| 47 | printf "Started at %d", $prog->program_start; | ||
| 48 | |||
| 49 | my $bench_postprint = Benchmark->new; | ||
| 50 | |||
| 51 | printf "\nTime to parse: %s\nTime to print: %s\n\n", | ||
| 52 | timestr( timediff( $bench_postparse, $bench_begin ) ), | ||
| 53 | timestr( timediff( $bench_postprint, $bench_postparse ) ); | ||
| 54 |