|
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, |
@@ -607,51 +617,46 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r, |
607 | 617 |
|
608 | 618 | zone = 1; |
609 | 619 |
|
610 | | -#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); |
| 620 | +#if (nginx_version > 1027003) && defined(NGX_HTTP_UPSTREAM_MODIFY) && !defined(NGX_HTTP_UPSTREAM_CHECK) |
| 621 | + if (uscf->flags & NGX_HTTP_UPSTREAM_MODIFY) { |
| 622 | + peers = uscf->peer.data; |
| 623 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, uscf->host, ctx->rbtree->root, ctx->rbtree->sentinel, peers, buf); |
| 624 | + } else { |
| 625 | + for (peers = uscf->peer.data; peers; peers = peers->next) { |
| 626 | + ngx_http_upstream_rr_peers_rlock(peers); |
| 627 | + for (peer = peers->peer; peer; peer = peer->next) { |
| 628 | + p = ngx_cpymem(p, uscf->host.data, uscf->host.len); |
| 629 | + *p++ = NGX_HTTP_VHOST_TRAFFIC_STATUS_KEY_SEPARATOR; |
| 630 | + p = ngx_cpymem(p, peer->name.data, peer->name.len); |
| 631 | + |
| 632 | + dst.len = uscf->host.len + sizeof("@") - 1 + peer->name.len; |
| 633 | + |
| 634 | + rc = ngx_http_vhost_traffic_status_node_generate_key(r->pool, &key, &dst, type); |
| 635 | + if (rc != NGX_OK) { |
| 636 | + ngx_http_upstream_rr_peers_unlock(peers); |
| 637 | + return buf; |
| 638 | + } |
| 639 | + |
| 640 | + hash = ngx_crc32_short(key.data, key.len); |
| 641 | + node = ngx_http_vhost_traffic_status_node_lookup(ctx->rbtree, &key, hash); |
| 642 | + |
| 643 | + usn.weight = peer->weight; |
| 644 | + usn.max_fails = peer->max_fails; |
| 645 | + usn.fail_timeout = peer->fail_timeout; |
| 646 | + usn.backup = 0; |
| 647 | + usn.down = (peer->fails >= peer->max_fails || peer->down); |
| 648 | + usn.name = peer->name; |
| 649 | + |
| 650 | + if (node != NULL) { |
| 651 | + vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color; |
| 652 | + buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn); |
| 653 | + } else { |
| 654 | + buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, NULL); |
| 655 | + } |
| 656 | + p = dst.data; |
651 | 657 | } |
652 | | - p = dst.data; |
| 658 | + ngx_http_upstream_rr_peers_unlock(peers); |
653 | 659 | } |
654 | | - ngx_http_upstream_rr_peers_unlock(peers); |
655 | 660 | } |
656 | 661 | goto last; |
657 | 662 | #endif |
@@ -767,7 +772,9 @@ ngx_http_vhost_traffic_status_display_set_upstream_group(ngx_http_request_t *r, |
767 | 772 | } |
768 | 773 | } |
769 | 774 |
|
| 775 | +#if (nginx_version > 1027003) && defined(NGX_HTTP_UPSTREAM_MODIFY) && !defined(NGX_HTTP_UPSTREAM_CHECK) |
770 | 776 | last: |
| 777 | +#endif |
771 | 778 | if (s == buf) { |
772 | 779 | buf = o; |
773 | 780 |
|
@@ -989,4 +996,57 @@ ngx_http_vhost_traffic_status_display_set(ngx_http_request_t *r, |
989 | 996 | return buf; |
990 | 997 | } |
991 | 998 |
|
| 999 | +#if (nginx_version > 1027003) && defined(NGX_HTTP_UPSTREAM_MODIFY) && !defined(NGX_HTTP_UPSTREAM_CHECK) |
| 1000 | +static u_char * |
| 1001 | +ngx_http_vhost_traffic_status_display_ug_host( |
| 1002 | + ngx_http_request_t *r, |
| 1003 | + ngx_str_t host, |
| 1004 | + ngx_rbtree_node_t *node, |
| 1005 | + ngx_rbtree_node_t *sentinel, |
| 1006 | + ngx_http_upstream_rr_peers_t *peers, |
| 1007 | + u_char *buf) |
| 1008 | +{ |
| 1009 | + ngx_int_t rc; |
| 1010 | + ngx_http_upstream_server_t usn; |
| 1011 | + ngx_http_upstream_rr_peer_t *peer; |
| 1012 | + ngx_http_upstream_rr_peers_t *base_peers; |
| 1013 | + ngx_http_vhost_traffic_status_node_t *vtsn; |
| 1014 | + |
| 1015 | + base_peers = peers; |
| 1016 | + if (node != sentinel) { |
| 1017 | + vtsn = (ngx_http_vhost_traffic_status_node_t *) &node->color; |
| 1018 | + if (vtsn->stat_upstream.type == NGX_HTTP_VHOST_TRAFFIC_STATUS_UPSTREAM_UG) { |
| 1019 | + rc = ngx_memn2cmp(host.data, vtsn->data+3, host.len, (size_t) host.len); |
| 1020 | + if (rc == 0) { |
| 1021 | + usn.name.data = vtsn->data + 3 + host.len + 1; |
| 1022 | + usn.name.len = vtsn->len - host.len - 4; |
| 1023 | + usn.weight = 0; |
| 1024 | + usn.max_fails = 0; |
| 1025 | + usn.fail_timeout = 0; |
| 1026 | + usn.backup = 0; |
| 1027 | + usn.down = 0; |
| 1028 | + while (peers != NULL) { |
| 1029 | + ngx_http_upstream_rr_peers_rlock(peers); |
| 1030 | + for (peer = peers->peer; peer; peer = peer->next) { |
| 1031 | + rc = ngx_memn2cmp(peer->name.data, usn.name.data, peer->name.len, (size_t) usn.name.len); |
| 1032 | + if (rc == 0) { |
| 1033 | + usn.weight = peer->weight; |
| 1034 | + usn.max_fails = peer->max_fails; |
| 1035 | + usn.fail_timeout = peer->fail_timeout; |
| 1036 | + usn.backup = 0; |
| 1037 | + usn.down = (peer->fails >= peer->max_fails || peer->down); |
| 1038 | + } |
| 1039 | + } |
| 1040 | + ngx_http_upstream_rr_peers_unlock(peers); |
| 1041 | + peers = peers->next; |
| 1042 | + } |
| 1043 | + buf = ngx_http_vhost_traffic_status_display_set_upstream_node(r, buf, &usn, vtsn); |
| 1044 | + } |
| 1045 | + } |
| 1046 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, host, node->left, sentinel, base_peers, buf); |
| 1047 | + buf = ngx_http_vhost_traffic_status_display_ug_host(r, host, node->right, sentinel, base_peers, buf); |
| 1048 | + } |
| 1049 | + return buf; |
| 1050 | +} |
| 1051 | +#endif |
992 | 1052 | /* vi:set ft=c ts=4 sw=4 et fdm=marker: */ |
0 commit comments