1

任何人都知道或使用过 Monit::HTTP 模块通过 HTTP 连接到监控守护进程的 perl 模块?

我正在尝试为 perl 使用 Monit::HTTP 模块,但遇到了一些麻烦。我无法检索状态变量,例如,monit status 命令给我 Status = Running 我在我的系统中运行的一些服务,但 Monit::HTTP 一直给我 Status=0。我尝试使用 monit stop 命令停止服务,我知道该进程已被终止,但 Monit::HTTP 以同样的方式给我 Status = 0。在最后一种情况下,状态 = 0 表示“服务已停止”或“服务正在运行”?

我的代码摘录从我的系统中检索性能数据,由 monit 守护程序监控:

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

在最后一种情况下,我无法从 monit 中检索到好的数据(在使用 Data::Dumper 模块获得的下一个 hash_ref 转储中查找 undef 数据),例如 Monit::HTTP 返回:

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',
};

监控状态命令返回:

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

我的代码摘录从我的进程(例如,apache 进程)中检索性能数据,由 monit 守护进程监控:

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

感谢您的支持。

4

1 回答 1

0

Monit::HTTP 通过 HTTP 协议连接到 Monit。您是否检查过 Monit 正在接受 HTTP 连接并且您的脚本连接到正确的参数?

wget -nd -v -O - --user 用户名 --password 密码 -- http://:/_status?format=xml

但也许问题更微不足道?您询问了 TYPE_PROCESS 并得到了回复:'type'=> '5';

如果您需要所有类型,您应该执行以下操作:(像 TYPE_ALL=-1 这样的模块中的 contans 会更加用户友好)

my @systems = $hd->get_services(-1);
foreach my $system (@systems) {
    print "system: $system\n";
    my $hash_ref = $hd->service_status($system);
于 2012-12-07T09:33:35.200 回答