简体   繁体   English

存取PHP受保护的物件属性(haproxy)

[英]Access PHP protected object property (haproxy)

I'm using a modified version of this library ( https://github.com/kamermans/HAProxyAPI ) to connect to all my loadbalancer instances. 我正在使用此库的修改版本( https://github.com/kamermans/HAProxyAPI )连接到我的所有loadbalancer实例。 However, to know whether servers connected are active instances or backup instances I need to adress 'bck' property from the statistics. 但是,要知道连接的服务器是活动实例还是备份实例,我需要从统计信息中获取“ bck”属性。 (I cannot access it using: $loadbalancer['haproxy_stats']->info->line->data->bck) (我无法使用以下方式访问它:$ loadbalancer ['haproxy_stats']-> info-> line-> data-> bck)

Note that this property: $loadbalancer['haproxy_stats']->health->backup. 请注意,此属性:$ loadbalancer ['haproxy_stats']-> health-> backup。 is not the one I need, this only indicates whether backup servers are present in this loadbalancer. 不是我需要的服务器,这仅表明此负载均衡器中是否存在备份服务器。

How do I access this property? 如何访问此属性?

Example Haproxy Stats from: HAProxy_Stats::get($exec)->getServiceStats($interface,$server); 示例Haproxy Stats,来自:HAProxy_Stats :: get($ exec)-> getServiceStats($ interface,$ server);

The result (print_r) looks like this: 结果(print_r)如下所示:

HAProxy_Stats_Service Object ( [info] => HAProxy_Stats_Info Object ( [map:protected] => Array ( [pxname] => proxy_name [svname] => service_name [weight] => weight [pid] => process_id [iid] => proxy_id [sid] => service_id [tracked] => tracked [type] => type ) HAProxy_Stats_Service对象([info] => HAProxy_Stats_Info对象([map:protected] =>数组([pxname] => proxy_name [svname] => service_name [weight] => weight [pid] => process_id [iid] => proxy_id [sid] => service_id [tracked] => tracked [type] => type)

        [type] => 2
        [proxy_name] => core_loadbalancer
        [service_name] => Core03
        [process_id] => 1
        [proxy_id] => 2
        [service_id] => 3
        [weight] => 1
        [tracked] => 
        [line:protected] => HAProxy_Stats_Line Object
            (
                [data:protected] => Array
                    (
                        [pxname] => core_loadbalancer
                        [svname] => Core03
                        [qcur] => 0
                        [qmax] => 0
                        [scur] => 0
                        [smax] => 0
                        [slim] => 20000
                        [stot] => 0
                        [bin] => 0
                        [bout] => 0
                        [dreq] => 
                        [dresp] => 0
                        [ereq] => 
                        [econ] => 0
                        [eresp] => 0
                        [wretr] => 0
                        [wredis] => 0
                        [status] => UP
                        [weight] => 1
                        [act] => 0
                        [bck] => 1
                        [chkfail] => 6
                        [chkdown] => 0
                        [lastchg] => 523133
                        [downtime] => 0
                        [qlimit] => 
                        [pid] => 1
                        [iid] => 2
                        [sid] => 3
                        [throttle] => 
                        [lbtot] => 0
                        [tracked] => 
                        [type] => 2
                        [rate] => 0
                        [rate_lim] => 
                        [rate_max] => 0
                        [check_status] => L4OK
                        [check_code] => 
                        [check_duration] => 0
                        [hrsp_1xx] => 0
                        [hrsp_2xx] => 0
                        [hrsp_3xx] => 0
                        [hrsp_4xx] => 0
                        [hrsp_5xx] => 0
                        [hrsp_other] => 0
                        [hanafail] => 0
                        [req_rate] => 
                        [req_rate_max] => 
                        [req_tot] => 
                        [cli_abrt] => 0
                        [srv_abrt] => 0
                        [] => 
                    )

            )

    )

The object continues but there is a character limit... 对象继续,但是有一个字符限制...

This would have been answered much sooner if an issue was created for it , but better late than never I guess :) 如果为它创建了一个问题,早就可以解决这个问题 ,但总比没有好,我迟到了:)

This is indeed the right property: 这确实是正确的属性:

$loadbalancer['haproxy_stats']->health->backup

But, if you are checking the stats of the loadbalancer BACKEND, it will just return the number of backup nodes. 但是,如果您正在检查负载均衡器BACKEND的统计信息,它将仅返回备份节点的数量。 If you want to know if individual nodes are active or backup, you will need to iterate over them like this: 如果您想知道单个节点是活动的还是备份的,则需要像这样迭代它们:

foreach ($stats->getBackendNames() as $backend) {
    foreach ($stats->getServerNames($backend) as $server) {
        $service = $stats->getServiceStats($backend, $server);
        echo "$backend:$server\n";
        echo "  Active: {$service->health->active}\n";
        echo "  Backup: {$service->health->backup}\n";
        echo "  Health: {$service->health->status}\n\n";
    }
}

This will produce output like this: 这将产生如下输出:

foo-cloud:FRONTEND
  Active: 
  Backup: 
  Health: OPEN

production-nodes:hiphop-node01-us.foocloud.com
  Active: 1
  Backup: 0
  Health: UP

production-nodes:apache-node01-us.foocloud.com
  Active: 0
  Backup: 1
  Health: UP

production-nodes:hiphop-node02-us.foocloud.com
  Active: 1
  Backup: 0
  Health: UP

production-nodes:apache-node02-us.foocloud.com
  Active: 0
  Backup: 1
  Health: MAINT

production-nodes:BACKEND
  Active: 2
  Backup: 2
  Health: UP

stats:FRONTEND
  Active: 
  Backup: 
  Health: OPEN

stats:BACKEND
  Active: 0
  Backup: 0
  Health: UP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM