|
14 | 14 | #include "ngx_http_upstream_check_module.h" |
15 | 15 | #endif |
16 | 16 |
|
| 17 | +static u_char * |
| 18 | +ngx_http_vhost_traffic_status_display_ug_host( |
| 19 | + ngx_http_request_t *r, |
| 20 | + ngx_str_t host, |
| 21 | + ngx_rbtree_node_t *node, |
| 22 | + ngx_rbtree_node_t *sentinel, |
| 23 | + ngx_http_upstream_rr_peers_t *peers, |
| 24 | + u_char *buf); |
17 | 25 |
|
18 | 26 | u_char * |
19 | 27 | ngx_http_vhost_traffic_status_display_set_main(ngx_http_request_t *r, |
@@ -608,51 +616,53 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r, |
608 | 616 | zone = 1; |
609 | 617 |
|
610 | 618 | #if nginx_version > 1027003 |
611 | | - for (peers = uscf->peer.data; peers; peers = peers->next) { |
612 | | - ngx_http_upstream_rr_peers_rlock(peers); |
613 | | - for (peer = peers->peer; peer; peer = peer->next) { |
614 | | - p = ngx_cpymem(p, uscf->host.data, uscf->host.len); |
615 | | - *p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR; |
616 | | - p = ngx_cpymem(p, peer->name.data, peer->name.len); |
617 | | - |
618 | | - dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len; |
619 | | - |
620 | | - rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type); |
621 | | - if (rc != NGX_OK) { |
622 | | - ngx_http_upstream_rr_peers_unlock(peers); |
623 | | - return buf; |
624 | | - } |
625 | | - |
626 | | - hash = ngx_crc32_short(key.data, key.len); |
627 | | - node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash); |
628 | | - |
629 | | - usn.weight = peer->weight; |
630 | | - usn.max_fails = peer->max_fails; |
631 | | - usn.fail_timeout = peer->fail_timeout; |
632 | | - usn.backup = 0; |
633 | | -#if (NGX_HTTP_UPSTREAM_CHECK) |
634 | | - if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
635 | | - usn.down = 1; |
636 | | - |
637 | | - } else { |
638 | | - usn.down = 0; |
639 | | - } |
640 | | -#else |
641 | | - usn.down = (peer->fails >= peer->max_fails || peer->down); |
642 | | -#endif |
643 | | - |
644 | | - usn.name = peer->name; |
645 | | - |
646 | | - if (node != NULL) { |
647 | | - vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color; |
648 | | - buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn); |
649 | | - } else { |
650 | | - buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL); |
651 | | - } |
652 | | - p = dst.data; |
653 | | - } |
654 | | - ngx_http_upstream_rr_peers_unlock(peers); |
655 | | - } |
| 619 | +// for (peers = uscf->peer.data; peers; peers = peers->next) { |
| 620 | +// ngx_http_upstream_rr_peers_rlock(peers); |
| 621 | +// for (peer = peers->peer; peer; peer = peer->next) { |
| 622 | +// p = ngx_cpymem(p, uscf->host.data, uscf->host.len); |
| 623 | +// *p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR; |
| 624 | +// p = ngx_cpymem(p, peer->name.data, peer->name.len); |
| 625 | +// |
| 626 | +// dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len; |
| 627 | +// |
| 628 | +// rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type); |
| 629 | +// if (rc != NGX_OK) { |
| 630 | +// ngx_http_upstream_rr_peers_unlock(peers); |
| 631 | +// return buf; |
| 632 | +// } |
| 633 | +// |
| 634 | +// hash = ngx_crc32_short(key.data, key.len); |
| 635 | +// node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash); |
| 636 | +// |
| 637 | +// usn.weight = peer->weight; |
| 638 | +// usn.max_fails = peer->max_fails; |
| 639 | +// usn.fail_timeout = peer->fail_timeout; |
| 640 | +// usn.backup = 0; |
| 641 | +//#if (NGX_HTTP_UPSTREAM_CHECK) |
| 642 | +// if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 643 | +// usn.down = 1; |
| 644 | +// |
| 645 | +// } else { |
| 646 | +// usn.down = 0; |
| 647 | +// } |
| 648 | +//#else |
| 649 | +// usn.down = (peer->fails >= peer->max_fails || peer->down); |
| 650 | +//#endif |
| 651 | +// |
| 652 | +// usn.name = peer->name; |
| 653 | +// |
| 654 | +// if (node != NULL) { |
| 655 | +// vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color; |
| 656 | +// buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn); |
| 657 | +// } else { |
| 658 | +// buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL); |
| 659 | +// } |
| 660 | +// p = dst.data; |
| 661 | +// } |
| 662 | +// ngx_http_upstream_rr_peers_unlock(peers); |
| 663 | +// } |
| 664 | + peers = uscf->peer.data; |
| 665 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, uscf->host, ctx->rbtree->root, ctx->rbtree->sentinel, peers, buf); |
656 | 666 | goto last; |
657 | 667 | #endif |
658 | 668 |
|
@@ -989,4 +999,64 @@ ngx_http_vhost_traffic_status_display_set(ngx_http_request_t *r, |
989 | 999 | return buf; |
990 | 1000 | } |
991 | 1001 |
|
| 1002 | +static u_char * |
| 1003 | +ngx_http_vhost_traffic_status_display_ug_host( |
| 1004 | + ngx_http_request_t *r, |
| 1005 | + ngx_str_t host, |
| 1006 | + ngx_rbtree_node_t *node, |
| 1007 | + ngx_rbtree_node_t *sentinel, |
| 1008 | + ngx_http_upstream_rr_peers_t *peers, |
| 1009 | + u_char *buf) |
| 1010 | +{ |
| 1011 | + ngx_int_t rc; |
| 1012 | + ngx_http_upstream_server_t usn; |
| 1013 | + ngx_http_upstream_rr_peer_t *peer; |
| 1014 | + ngx_http_upstream_rr_peers_t *base_peers; |
| 1015 | + ngx_http_vhost_traffic_status_node_t *vtsn; |
| 1016 | + |
| 1017 | + base_peers = peers; |
| 1018 | + if (node != sentinel) { |
| 1019 | + vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color; |
| 1020 | + if (vtsn->stat_upstream.type == NGX_HTTP_VHOST_TRAFFIC_STATUS_UPSTREAM_UG) { |
| 1021 | + rc = ngx_memn2cmp(host.data, vtsn->data+3, host.len, (size_t) host.len); |
| 1022 | + if (rc == 0) { |
| 1023 | + usn.name.data = vtsn->data + 3 + host.len + 1; |
| 1024 | + usn.name.len = vtsn->len - host.len - 4; |
| 1025 | + usn.weight = 0; |
| 1026 | + usn.max_fails = 0; |
| 1027 | + usn.fail_timeout = 0; |
| 1028 | + usn.backup = 0; |
| 1029 | + usn.down = 0; |
| 1030 | + while (peers != NULL) { |
| 1031 | + ngx_http_upstream_rr_peers_rlock(peers); |
| 1032 | + for (peer = peers->peer; peer; peer = peer->next) { |
| 1033 | + rc = ngx_memn2cmp(peer->name.data, usn.name.data, peer->name.len, (size_t) usn.name.len); |
| 1034 | + if (rc == 0) { |
| 1035 | + usn.weight = peer->weight; |
| 1036 | + usn.max_fails = peer->max_fails; |
| 1037 | + usn.fail_timeout = peer->fail_timeout; |
| 1038 | + usn.backup = 0; |
| 1039 | +#if (NGX_HTTP_UPSTREAM_CHECK) |
| 1040 | + if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
| 1041 | + usn.down = 1; |
| 1042 | + |
| 1043 | + } else { |
| 1044 | + usn.down = 0; |
| 1045 | + } |
| 1046 | +#else |
| 1047 | + usn.down = (peer->fails >= peer->max_fails || peer->down); |
| 1048 | +#endif |
| 1049 | + } |
| 1050 | + } |
| 1051 | + ngx_http_upstream_rr_peers_unlock(peers); |
| 1052 | + peers = peers->next; |
| 1053 | + } |
| 1054 | + buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn); |
| 1055 | + } |
| 1056 | + } |
| 1057 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, host, node->left, sentinel, base_peers, buf); |
| 1058 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, host, node->right, sentinel, base_peers, buf); |
| 1059 | + } |
| 1060 | + return buf; |
| 1061 | +} |
992 | 1062 | /* vi:set ft=c ts=4 sw=4 et fdm=marker: */ |
0 commit comments