【问题标题】:Undef data and process/system status obtained from Monit::HTTP perl module从 Monit::HTTP perl 模块获得的 undef 数据和进程/系统状态
【发布时间】:2012-12-06 15:40:44
【问题描述】:

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

我正在尝试为 perl 使用 Monit::HTTP 模块,但遇到了一些麻烦。 我无法检索状态变量,例如,monit status 命令给我 Status = Running 我在我的系统中运行的某些服务,但 Monit::HTTP 一直给我 Status=0。 我尝试使用 monit stop 命令停止服务,并且我知道该进程已被终止,但 Monit::HTTP 以同样的方式给我 Status = 0。 在最后一种情况下,Status = 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',
};

和monit status命令返回:

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);
...

感谢大家的支持。

【问题讨论】:

  • 你能把散列转储为散列参考吗? Data::Dumper::Dump 采用标量值列表,而不是哈希值。这样会更容易找到键值对,谢谢。

标签: perl monit


【解决方案1】:

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-27
    • 2019-09-23
    • 1970-01-01
    • 2011-06-22
    相关资源
    最近更新 更多