root/resmon

Revision b3c640775d36906eb2e9f8a2b1cbf1bbb0ba8fd4, 1.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

make this stuff object oriented.. but Resmon::Modules should really by Resmon::Module

git-svn-id: https://labs.omniti.com/resmon/trunk@20 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100755
Line 
1 #!/usr/bin/perl
2
3 use lib '/opt/resmon/lib';
4
5 use strict;
6 use Time::HiRes qw( gettimeofday tv_interval sleep );
7 use Data::Dumper;
8 use POSIX qw( setsid );
9 use Getopt::Long;
10 use vars qw($config_file $debug $status_file $config);
11
12 use Resmon::Config;
13 use Resmon::ExtComm;
14 use Resmon::Status;
15 use Resmon::Modules;
16
17 GetOptions(
18   "c=s" => \$config_file,
19   "d"   => \$debug,
20   "f=s" => \$status_file,
21 );
22
23 $config_file ||= 'resmon.conf';
24 die "Cannot open configuration file: $config_file" unless (-r $config_file);
25
26 sub configure {
27   $config = Resmon::Config->new($config_file);
28   $config->{statusfile} = $status_file if($status_file);
29   print Dumper($config) if($debug);
30 }
31 unless($debug) {
32   fork && exit;
33   setsid;
34 }
35 configure();
36 $SIG{'HUP'} = \&configure;
37
38 use Time::HiRes qw( gettimeofday tv_interval sleep );
39
40 my $rmlast = undef;
41 sub wait_interval {
42   $rmlast = [gettimeofday] unless defined($rmlast);
43   my $elapsed = $config->{interval} - tv_interval($rmlast);
44   if($elapsed > 0) {
45     sleep($elapsed);
46   }
47   $rmlast = [gettimeofday];
48 }
49
50 my $list = [];
51 my $status = Resmon::Status->new($config->{statusfile});
52 while(1) {
53   while(my($module_name, $mod_configs) = each %{$config->{Modules}}) {
54     my $coderef = Resmon::Modules::fetch_monitor($module_name);
55     foreach my $monobj (@$mod_configs) {
56       my $check_rv = 'BAD',
57       my $check_mess = 'no data';
58       if($coderef) {
59         eval { ($check_rv, $check_mess) = $coderef->($monobj); };
60       } else {
61         eval { ($check_rv, $check_mess) = $monobj->handler(); };
62       }
63       if($@) {
64         $status->store($module_name,$monobj->{'object'},'BAD',$@);
65       } else {
66         $status->store($module_name,$monobj->{'object'},$check_rv,$check_mess);
67       }
68     }
69   }
70   $status->close();
71   wait_interval();
72   print "\n---- ".localtime(time)."----------\n"
73     unless $status->open();
74 }
75
Note: See TracBrowser for help on using the browser.