2013-07-20 2 views
0

이 라이브러리의 수정 된 버전 (https://github.com/kamermans/HAProxyAPI)을 사용하여 모든로드 밸런서 인스턴스에 연결합니다. 그러나 연결된 서버가 활성 인스턴스인지 아니면 백업 인스턴스인지 여부를 확인하려면 통계에서 'bck'속성을 사용해야합니다. ($ loadbalancer [ 'haproxy_stats'] -> info-> line-> data-> bck)PHP 보호 객체 속성 (haproxy)

$ loadbalancer [ 'haproxy_stats'] -> health-> backup에주의하십시오. 필요한 것이 아니기 때문에 백업 서버가이로드 밸런서에 있는지 여부 만 나타냅니다.

어떻게이 속성에 액세스 할 수 있습니까?

예제 Haproxy 통계 : HAProxy_Stats :: get ($ exec) -> getServiceStats ($ interface, $ server);

HAProxy_Stats_Service 개체 ( [정보] = > HAProxy_Stats_Info 개체 ( [지도 : 보호] = > 배열 ( [pxname] = > proxy_name

결과 (인 print_r)은 다음과 같습니다 [svname] = > service_name [weight] = > weight [pid] = > process_id [iid] =,743,925,862,473,210는 는 [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 
         [] => 
        ) 

      ) 

    ) 
목적은 계속

하지만 문자 제한이을 ... 추적 proxy_id

답변

0

이는 것 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