Undef data and process/system status obtained from Monit::HTTP perl module

StackOverflow https://stackoverflow.com/questions/13747165

  •  05-12-2021
  •  | 
  •  

質問

Anyone knows or have used Monit::HTTP module for perl connection to monit daemon through HTTP?

I am trying to use Monit::HTTP module for perl and I have some troubles. I cannot retrieve status variable, for example, monit status command give me Status = Running for some services that i have running in my system but Monit::HTTP all time give me Status=0. I try to stop a service with monit stop command and i know that process was killed but Monit::HTTP give me Status = 0 for this in the same way. In that last case the Status = 0 mean "service stopped" or "service running"?

My code excerpt to retrieve performance data from my system monitored by monit daemon:

my @systems = $hd->get_services(TYPE_SYSTEM);
foreach my $system (@systems) {
  print "system: $system\n";
  my $hash_ref = $hd->service_status($system);
...

In this last case i cannot retrieve good data from monit (look for undef data in the next hash_ref dump which was obtained with Data::Dumper module), for example Monit::HTTP return:

system: xpto
$VAR1 = {
   'cpu' => {
       'percent' => undef,
       'percenttotal' => undef },
    'status' => '0',
    'name' => 'xpto',
    'children'=> undef,
    'monitor' => '1',
    'host' => 'localhost',
    'memory'=> {
        'percent' => undef,
        'kilobytetotal' => undef,
        'kilobyte' => undef,
        'percenttotal' => undef },
    'group' => undef,
    'pid' => undef;
    'ppid' => undef;
    'uptime' => undef;
    'type'=> '5';
    'load' => {
        'avg05' => undef,
        'avg01' => undef,
        'avg15' => undef },
    'pendingaction' => '0',
};

And monit status command return:

System 'xpto'
status                Running
monitoring status     Monitored
load average          [1.25] [1.16] [0.94]
cpu                   8.7%us 7.4%sy
memory usage          3202164 kB [76.3%]
swap usage            1589248 kB [75.7%]
data collected        Thu, 06 Dec 2012 11:50:55

My code excerpt to retrieve performance data from my processes (for example, apache process) monitored by monit daemon:

my @systems = $hd->get_services(TYPE_PROCESS);
foreach my $system (@systems) {
    print "system: $system\n";
    my $hash_ref = $hd->service_status($system);
...

Thanks for all your support.

役に立ちましたか?

解決

Monit::HTTP connects via HTTP protocol to Monit. Did you checked that Monit is accepting HTTP connection and you script connects to the right parameters?

wget -nd -v -O - --user username --password password -- http://:/_status?format=xml

But maybe the problem more trivial? You asked for TYPE_PROCESS and you get your response: 'type'=> '5';

If you need all types you should do the following: (a contans in the moddule like TYPE_ALL=-1 would be more user friendly)

my @systems = $hd->get_services(-1);
foreach my $system (@systems) {
    print "system: $system\n";
    my $hash_ref = $hd->service_status($system);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top