Print current running connections in nginx

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Print current running connections in nginx

redflag
Hi,

Status module prints the count of active connections.

Is there a way to fetch more details about currently running connections in
nginx like request uri, started time similar to Apache's extended status.

Thanks
Sachin

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,287673,287673#msg-287673

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Print current running connections in nginx

Mathew Heard-2
Sachin,

AFAIK Not easily. Each worker only knows about their own connections.
You would need to build a module using a shared memory zone to track
connections.

Regards,
Mathew

On 16/04/2020, [hidden email] <[hidden email]> wrote:

> Hi,
>
> Status module prints the count of active connections.
>
> Is there a way to fetch more details about currently running connections in
>
> nginx like request uri, started time similar to Apache's extended status.
>
> Thanks
> Sachin
>
> Posted at Nginx Forum:
> https://forum.nginx.org/read.php?2,287673,287673#msg-287673
>
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Print current running connections in nginx

Mathew Heard-2
In reply to this post by redflag
Sachin,

AFAIK Not easily. Each worker only knows about their own connections.
You would need to build a module using a shared memory zone to track
connections.

Regards,
Mathew

On 16/04/2020, [hidden email] <[hidden email]> wrote:

> Hi,
>
> Status module prints the count of active connections.
>
> Is there a way to fetch more details about currently running connections in
>
> nginx like request uri, started time similar to Apache's extended status.
>
> Thanks
> Sachin
>
> Posted at Nginx Forum:
> https://forum.nginx.org/read.php?2,287673,287673#msg-287673
>
> _______________________________________________
> nginx mailing list
> [hidden email]
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Print current running connections in nginx

redflag
In reply to this post by Mathew Heard-2
Thanks Mathew.

I thought about it and even prototyped it with openresty, but I am concerned
about ngx.shared.DICT.get_keys locking the whole dictionary and blocking
connections that are trying to add new incoming connections.

Is there some worker datastructure available that can be read and reported
from? The worker obviously knows all the connections it is handling and the
various states the connections are in. So it would be easy to iterate the
internal data structure with an ngx.timer.every timer.

Thanks
Sachin

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,287673,287676#msg-287676

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Print current running connections in nginx

Mathew Heard-2
This is a snippet from something I was experimenting with. I can't recall it actually worked, but it might help for a start. Good Luck.

ngx_cycle_t *cycle
for (i = 0; i < cycle->connection_n; i++) {
        c = &conns[i];
if (c->fd == (ngx_socket_t) -1 || c->idle || c->listening) continue;
hlc = (ngx_http_log_ctx_t*)c->log->data;
if(!hlc) continue;
        r = hlc->current_request;
        ngx_log_error(NGX_LOG_ERR, c->log, 0, "has hlc");
        if(!r) continue;
        ngx_log_error(NGX_LOG_ERR, c->log, 0, "has req");

On Thu, 16 Apr 2020 at 18:49, [hidden email] <[hidden email]> wrote:
Thanks Mathew.

I thought about it and even prototyped it with openresty, but I am concerned
about ngx.shared.DICT.get_keys locking the whole dictionary and blocking
connections that are trying to add new incoming connections.

Is there some worker datastructure available that can be read and reported
from? The worker obviously knows all the connections it is handling and the
various states the connections are in. So it would be easy to iterate the
internal data structure with an ngx.timer.every timer.

Thanks
Sachin

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,287673,287676#msg-287676

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Print current running connections in nginx

redflag
Best sample code:
https://github.com/vozlt/nginx-module-vts

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,287673,287680#msg-287680

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx