root/resmon

Revision e5d09e81c6b6816e904b241f852e542e067c2d4c, 2.0 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 12 years ago)

shm status support

git-svn-id: https://labs.omniti.com/resmon/trunk@26 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 POSIX qw( setsid );
8 use Getopt::Long;
9 use Data::Dumper;
10 use vars qw($config_file $debug $status_file $interface $port $config);
11
12 use Resmon::Config;
13 use Resmon::ExtComm;
14 use Resmon::Status;
15 use Resmon::Module;
16
17 GetOptions(
18   "i=s" => \$interface,
19   "p=i" => \$port,
20   "c=s" => \$config_file,
21   "d"   => \$debug,
22   "f=s" => \$status_file,
23 );
24
25 $config_file ||= 'resmon.conf';
26 die "Cannot open configuration file: $config_file" unless (-r $config_file);
27
28 sub configure {
29   $config = Resmon::Config->new($config_file);
30   $config->{statusfile} = $status_file if($status_file);
31 }
32
33 $SIG{'HUP'} = \&configure;
34 configure();
35
36 my $sigint = 0;
37 sub sigint_handler { $sigint = 1; }
38 $SIG{'INT'} = \&sigint_handler;
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 $status->open();
53 $status->serve_http_on($interface, $port) if($port);
54
55 unless($debug) {
56   fork && exit;
57   setsid;
58   close(STDIN);
59   close(STDOUT);
60   close(STDERR);
61   fork && exit;
62 }
63
64 while(1) {
65   while(my($module_name, $mod_configs) = each %{$config->{Module}}) {
66     my $coderef = Resmon::Module::fetch_monitor($module_name);
67     foreach my $monobj (@$mod_configs) {
68       my $check_rv = 'BAD',
69       my $check_mess = 'no data';
70       if($coderef) {
71         eval { ($check_rv, $check_mess) = $coderef->($monobj); };
72       } else {
73         eval { ($check_rv, $check_mess) = $monobj->handler(); };
74       }
75       if($@) {
76         $status->store($module_name,$monobj->{'object'},'BAD',$@);
77       } else {
78         $status->store($module_name,$monobj->{'object'},$check_rv,$check_mess);
79       }
80     }
81   }
82   $status->close();
83   die "Exiting.\n" if($sigint);
84   wait_interval();
85   die "Exiting.\n" if($sigint);
86   print "\n---- ".localtime(time)."----------\n"
87    unless $status->open();
88 }
89
Note: See TracBrowser for help on using the browser.