|
14 | 14 | #include "ngx_http_upstream_check_module.h" |
15 | 15 | #endif |
16 | 16 |
|
| 17 | +#if (nginx_version > 1027003) && defined(NGX_HTTP_UPSTREAM_MODIFY) && !defined(NGX_HTTP_UPSTREAM_CHECK) |
| 18 | +static u_char * |
| 19 | +ngx_http_vhost_traffic_status_display_ug_host( |
| 20 | + ngx_http_request_t *r, |
| 21 | + ngx_str_t host, |
| 22 | + ngx_rbtree_node_t *node, |
| 23 | + ngx_rbtree_node_t *sentinel, |
| 24 | + ngx_http_upstream_rr_peers_t *peers, |
| 25 | + u_char *buf); |
| 26 | +#endif |
17 | 27 |
|
18 | 28 | u_char * |
19 | 29 | ngx_http_vhost_traffic_status_display_set_main(ngx_http_request_t *r, |
@@ -633,51 +643,46 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r, |
633 | 643 |
|
634 | 644 | zone = 1; |
635 | 645 |
|
636 | | -#if nginx_version > 1027003 |
637 | | - for (peers = uscf->peer.data; peers; peers = peers->next) { |
638 | | - ngx_http_upstream_rr_peers_rlock(peers); |
639 | | - for (peer = peers->peer; peer; peer = peer->next) { |
640 | | - p = ngx_cpymem(p, uscf->host.data, uscf->host.len); |
641 | | - *p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR; |
642 | | - p = ngx_cpymem(p, peer->name.data, peer->name.len); |
643 | | - |
644 | | - dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len; |
645 | | - |
646 | | - rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type); |
647 | | - if (rc != NGX_OK) { |
648 | | - ngx_http_upstream_rr_peers_unlock(peers); |
649 | | - return buf; |
650 | | - } |
651 | | - |
652 | | - hash = ngx_crc32_short(key.data, key.len); |
653 | | - node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash); |
654 | | - |
655 | | - usn.weight = peer->weight; |
656 | | - usn.max_fails = peer->max_fails; |
657 | | - usn.fail_timeout = peer->fail_timeout; |
658 | | - usn.backup = 0; |
659 | | -#if (NGX_HTTP_UPSTREAM_CHECK) |
660 | | - if (ngx_http_upstream_check_peer_down(peer->check_index)) { |
661 | | - usn.down = 1; |
662 | | - |
663 | | - } else { |
664 | | - usn.down = 0; |
665 | | - } |
666 | | -#else |
667 | | - usn.down = (peer->fails >= peer->max_fails || peer->down); |
668 | | -#endif |
669 | | - |
670 | | - usn.name = peer->name; |
671 | | - |
672 | | - if (node != NULL) { |
673 | | - vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color; |
674 | | - buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn); |
675 | | - } else { |
676 | | - buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL); |
| 646 | +#if (nginx_version > 1027003) && defined(NGX_HTTP_UPSTREAM_MODIFY) && !defined(NGX_HTTP_UPSTREAM_CHECK) |
| 647 | + if (uscf->flags & NGX_HTTP_UPSTREAM_MODIFY) { |
| 648 | + peers = uscf->peer.data; |
| 649 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, uscf->host, ctx->rbtree->root, ctx->rbtree->sentinel, peers, buf); |
| 650 | + } else { |
| 651 | + for (peers = uscf->peer.data; peers; peers = peers->next) { |
| 652 | + ngx_http_upstream_rr_peers_rlock(peers); |
| 653 | + for (peer = peers->peer; peer; peer = peer->next) { |
| 654 | + p = ngx_cpymem(p, uscf->host.data, uscf->host.len); |
| 655 | + *p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR; |
| 656 | + p = ngx_cpymem(p, peer->name.data, peer->name.len); |
| 657 | + |
| 658 | + dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len; |
| 659 | + |
| 660 | + rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type); |
| 661 | + if (rc != NGX_OK) { |
| 662 | + ngx_http_upstream_rr_peers_unlock(peers); |
| 663 | + return buf; |
| 664 | + } |
| 665 | + |
| 666 | + hash = ngx_crc32_short(key.data, key.len); |
| 667 | + node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash); |
| 668 | + |
| 669 | + usn.weight = peer->weight; |
| 670 | + usn.max_fails = peer->max_fails; |
| 671 | + usn.fail_timeout = peer->fail_timeout; |
| 672 | + usn.backup = 0; |
| 673 | + usn.down = (peer->fails >= peer->max_fails || peer->down); |
| 674 | + usn.name = peer->name; |
| 675 | + |
| 676 | + if (node != NULL) { |
| 677 | + vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color; |
| 678 | + buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn); |
| 679 | + } else { |
| 680 | + buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL); |
| 681 | + } |
| 682 | + p = dst.data; |
677 | 683 | } |
678 | | - p = dst.data; |
| 684 | + ngx_http_upstream_rr_peers_unlock(peers); |
679 | 685 | } |
680 | | - ngx_http_upstream_rr_peers_unlock(peers); |
681 | 686 | } |
682 | 687 | goto last; |
683 | 688 | #endif |
@@ -793,7 +798,9 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r, |
793 | 798 | } |
794 | 799 | } |
795 | 800 |
|
| 801 | +#if (nginx_version > 1027003) && defined(NGX_HTTP_UPSTREAM_MODIFY) && !defined(NGX_HTTP_UPSTREAM_CHECK) |
796 | 802 | last: |
| 803 | +#endif |
797 | 804 | if (s == buf) { |
798 | 805 | buf = o; |
799 | 806 |
|
@@ -1020,4 +1027,57 @@ ngx_http_vhost_traffic_status_display_set(ngx_http_request_t *r, |
1020 | 1027 | return buf; |
1021 | 1028 | } |
1022 | 1029 |
|
| 1030 | +#if (nginx_version > 1027003) && defined(NGX_HTTP_UPSTREAM_MODIFY) && !defined(NGX_HTTP_UPSTREAM_CHECK) |
| 1031 | +static u_char * |
| 1032 | +ngx_http_vhost_traffic_status_display_ug_host( |
| 1033 | + ngx_http_request_t *r, |
| 1034 | + ngx_str_t host, |
| 1035 | + ngx_rbtree_node_t *node, |
| 1036 | + ngx_rbtree_node_t *sentinel, |
| 1037 | + ngx_http_upstream_rr_peers_t *peers, |
| 1038 | + u_char *buf) |
| 1039 | +{ |
| 1040 | + ngx_int_t rc; |
| 1041 | + ngx_http_upstream_server_t usn; |
| 1042 | + ngx_http_upstream_rr_peer_t *peer; |
| 1043 | + ngx_http_upstream_rr_peers_t *base_peers; |
| 1044 | + ngx_http_vhost_traffic_status_node_t *vtsn; |
| 1045 | + |
| 1046 | + base_peers = peers; |
| 1047 | + if (node != sentinel) { |
| 1048 | + vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color; |
| 1049 | + if (vtsn->stat_upstream.type == NGX_HTTP_VHOST_TRAFFIC_STATUS_UPSTREAM_UG) { |
| 1050 | + rc = ngx_memn2cmp(host.data, vtsn->data+3, host.len, (size_t) host.len); |
| 1051 | + if (rc == 0) { |
| 1052 | + usn.name.data = vtsn->data + 3 + host.len + 1; |
| 1053 | + usn.name.len = vtsn->len - host.len - 4; |
| 1054 | + usn.weight = 0; |
| 1055 | + usn.max_fails = 0; |
| 1056 | + usn.fail_timeout = 0; |
| 1057 | + usn.backup = 0; |
| 1058 | + usn.down = 0; |
| 1059 | + while (peers != NULL) { |
| 1060 | + ngx_http_upstream_rr_peers_rlock(peers); |
| 1061 | + for (peer = peers->peer; peer; peer = peer->next) { |
| 1062 | + rc = ngx_memn2cmp(peer->name.data, usn.name.data, peer->name.len, (size_t) usn.name.len); |
| 1063 | + if (rc == 0) { |
| 1064 | + usn.weight = peer->weight; |
| 1065 | + usn.max_fails = peer->max_fails; |
| 1066 | + usn.fail_timeout = peer->fail_timeout; |
| 1067 | + usn.backup = 0; |
| 1068 | + usn.down = (peer->fails >= peer->max_fails || peer->down); |
| 1069 | + } |
| 1070 | + } |
| 1071 | + ngx_http_upstream_rr_peers_unlock(peers); |
| 1072 | + peers = peers->next; |
| 1073 | + } |
| 1074 | + buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn); |
| 1075 | + } |
| 1076 | + } |
| 1077 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, host, node->left, sentinel, base_peers, buf); |
| 1078 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, host, node->right, sentinel, base_peers, buf); |
| 1079 | + } |
| 1080 | + return buf; |
| 1081 | +} |
| 1082 | +#endif |
1023 | 1083 | /* vi:set ft=c ts=4 sw=4 et fdm=marker: */ |
0 commit comments