【问题标题】:Access PHP protected object property (haproxy)访问 PHP 保护对象属性(haproxy)
【发布时间】:2013-07-19 16:47:03
【问题描述】:

我正在使用该库的修改版本 (https://github.com/kamermans/HAProxyAPI) 连接到我的所有负载均衡器实例。 但是,要知道连接的服务器是活动实例还是备份实例,我需要从统计数据中处理“bck”属性。 (我无法使用:$loadbalancer['haproxy_stats']->info->line->data->bck)

注意这个属性:$loadbalancer['haproxy_stats']->health->backup。不是我需要的,这仅表明此负载均衡器中是否存在备份服务器。

如何访问此属性?

示例 Haproxy 统计数据来自:HAProxy_Stats::get($exec)->getServiceStats($interface,$server);

结果(print_r)如下所示:

HAProxy_Stats_Service 对象 ( [信息] => HAProxy_Stats_Info 对象 ( [地图:受保护] => 数组 ( [pxname] => 代理名称 [svname] => 服务名称 [重量] => 重量 [pid] => process_id [iid] => proxy_id [sid] => service_id [跟踪] => 跟踪 [类型] => 类型 )

        [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
                        [] => 
                    )

            )

    )

对象继续,但有字符限制...

【问题讨论】:

    标签: php object properties private haproxy


    【解决方案1】:

    如果issue was created for it 会更快得到答复,但我猜迟到总比没有好:)

    这确实是正确的属性:

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

    但是,如果您正在检查负载均衡器 BACKEND 的统计信息,它只会返回备份节点的数量。如果您想知道各个节点是活动的还是备用的,您需要像这样迭代它们:

    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";
        }
    }
    

    这将产生如下输出:

    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
    

    【讨论】:

      猜你喜欢
      • 2013-10-02
      • 2013-01-05
      • 2019-10-06
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多