Hello!
The direction is correct but your systemtap script has bugs itself.
For example, ngx_cycle itself is a pointer, addressing it with "&"
again turn it into something else. Also, ngx_cycle->files is an
instance of ngx_list_t, whose ->size field is not what you want (it's
just the size of each element in the queue, not the size of the
queue).
I've just tweaked your script and come up with this:
https://github.com/openresty/stapxx/blob/master/samples/ngx-count-conns.sxx
I've added it as a sample tool for my stap++ wrapper for systemtap.
Hopefully you don't mind :)
Also added some docs for it:
https://github.com/openresty/stapxx#ngx-count-conns
One sample output in a production box:
$ ngx-count-conns.sxx -x 32743
Start tracing 32743 (/opt/nginx/sbin/nginx)...
====== CONNECTIONS ======
Max connections: 32768
Free connections: 27674
Used connections: 5094
====== FILES ======
Max files: 131072
Open files: 2
Free files: 131070
Regarding your questions, yes, ngx_lua's cosocket connections and
timers are also counted in the "Used connections" numbers shown above.
Regards,
-agentzh