Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Howto get upstreams state #262

Closed
adrimt opened this issue Mar 2, 2023 · 5 comments
Closed

Howto get upstreams state #262

adrimt opened this issue Mar 2, 2023 · 5 comments

Comments

@adrimt
Copy link

adrimt commented Mar 2, 2023

Hi,
the upstream state is always 'UP' even when the backend serer is down and the nginx return code is 502.
Did I miss something ?

vhost_traffic_status_zone;
geoip_country /usr/share/GeoIP/GeoIP.dat;
vhost_traffic_status_filter_by_set_key $geoip_country_code country::*;
vhost_traffic_status_zone shared:vhost_traffic_status:32m;

server {
listen 10.10.10.1:80;
server_name $hostname;
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
access_log off;
}
}
server {
listen 10.10.10.10:80;
server_name webserver1;
location / {
proxy_pass http://192.168.10.10;
...
}
}

@u5surf
Copy link
Collaborator

u5surf commented Mar 2, 2023

@adrimt Thanks reporting!
The other days, we had catch the same issue #258 (comment)
Then it could resolve the upstream zone.
Can you check this setting is existed on your nginx.conf (I could not find out upstream directive above config)

@adrimt
Copy link
Author

adrimt commented Mar 3, 2023

I change the config to define an "upstream" but it didn't behave differently.
The "check" directive is unavailable on my free nginx.

upstream web01-http {
zone backend 64k;
server 192.168.10.10:80;
}

server {
listen 10.10.10.10:80;
server_name webserver1;
location / {
proxy_pass http://web01-http;
...
}

@u5surf
Copy link
Collaborator

u5surf commented Mar 5, 2023

@adrimt
This module seems to display whether the upstream state is down or not to watch the peer.down when display mode is html ( json mode is slightly different behavior on that #258 (comment))

aHe('td', [sTh(peer.backup, peer.down), mTh(peer.responseMsec),

Moreover nginx oss doesn't change peer->down anywhere below.

% rg "peer->down" ./src
./src/stream/ngx_stream_upstream_round_robin.c
461:        if (peer->down) {
559:        if (peer->down) {

./src/stream/ngx_stream_upstream_hash_module.c
235:        if (peer->down) {
549:            if (peer->down) {

./src/stream/ngx_stream_upstream_least_conn_module.c
142:        if (peer->down) {
197:            if (peer->down) {

./src/stream/ngx_stream_upstream_random_module.c
248:        if (peer->down) {
350:        if (peer->down) {

./src/http/ngx_http_upstream_round_robin.c
452:        if (peer->down) {
550:        if (peer->down) {

./src/http/modules/ngx_http_upstream_ip_hash_module.c
206:        if (peer->down) {

./src/http/modules/ngx_http_upstream_random_module.c
248:        if (peer->down) {
350:        if (peer->down) {

./src/http/modules/ngx_http_upstream_least_conn_module.c
146:        if (peer->down) {
201:            if (peer->down) {

./src/http/modules/ngx_http_upstream_hash_module.c
236:        if (peer->down) {
548:            if (peer->down) {

We should match the behavior due to display mode both html and json.
By fixing this behavior, we can observe the upstream down to use nginx_upstream_check_module on workaround.

@u5surf
Copy link
Collaborator

u5surf commented Mar 9, 2023

@adrimt
Hi, We end up checking the nginx upstream spec which the peer is single via nginx-dev ML. its answer is here.
https://mailman.nginx.org/pipermail/nginx-devel/2023-March/Q6MCXGQU56HDD7K2BWRYLCUEC7VBPUV4.html

As per nginx usage of upstreams with a single peer, such peers are
never considered unavailable, and to do this failures are never
counted (or, which is equivalent, immediately forgotten). If you are trying to show status of a peer as seen by nginx, then
"up" is perfectly correct for such peers.

Thus, we could not fix the view point of peer->fails with peers->single by any nginx upstream patch.

you should look into request results (and/or upstream states), and collect relevant stats yourself.

So we should embed other request based module to collect such stats, e.g. we can use nginx_upstream_check_module on workaround.

compile with pure nginx

$ git clone https://github.com/yaoweibin/nginx_upstream_check_module
$ cd /path/to/nginx # latest
$ patch -p1 < /path/to/nginx_upstream_check_module/check_1.20.1+patch
$ ./auto/configure --add-module=/path/to/nginx-module-vts --add-module=/path/to/nginx_upstream_check_module
$ make
$ sudo make install

nginx.conf


http {
...
    vhost_traffic_status_zone;
    upstream web {
            zone backend 64k; # <- here
            check interval=5000 rise=1 fall=3 timeout=4000;
            server 127.0.0.1:8080;
    }
    server {
        listen       8000;
        location / {
            proxy_pass http://web;
        }
    }
    server {
        listen       80;
        location /status/ {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
    }
}

The upstream peer is up

26D63218-46DA-407B-AB0E-625F2B075E30

otherwise
CE32D33E-A076-4655-96DE-A58ACBFDCF72

@adrimt
Copy link
Author

adrimt commented Mar 9, 2023

Thank you for clarifying this issue.

@adrimt adrimt closed this as completed Mar 9, 2023
u5surf added a commit to u5surf/nginx-module-vts that referenced this issue Mar 12, 2023
u5surf added a commit to u5surf/nginx-module-vts that referenced this issue Mar 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants