3

Before

Until recently I used nginx 1.4.x with zebrafishlabs/nginx-statsd as a reverse proxy for openresty (yes, I know, nginx behind nginx is stupid - keep reading please) with the following location nginx configuration:

location /track {
  statsd_count "tracker.track_$scheme" 1;
  proxy_pass http://localhost:10081/track;
  proxy_set_header Host $host;
}

..and the following location openresty (listening on port 10081 TCP, of course) config:

location /track {
  content_by_lua_file 'conf/track.lua';
}

..and it worked. Please note that I have a few locations like that - it is important, you will see later on.

Stats were being pushed to statsd and the scripts were executed.


Now

Recently I decided to remove the front end nginx and use openresty alone.

Now I am using openresty 1.5.12.1 with zebrafishlabs/nginx-statsd compiled in and the following (obvious) configuration:

location /track {
  statsd_count "tracker.track_$scheme" 1;
  content_by_lua_file 'conf/track.lua';
}

But after this change sometimes my stats are not being pushed to statsd.

Apparently it happens if my lua script end execution with ngx.redirect lua command..

I tried to use this config as a workaround:

location /track {
  statsd_count "tracker.track_$scheme" 1;
  proxy_pass http://127.0.0.1/track-do;
}

location /track-do {
  content_by_lua_file 'conf/track.lua';
}

...but I got really strange results:

When I changed my "track" location this way it started to work properly - all stats pushed to statsd, code executed.

..but at the same time my other location, "static", that was not changed stopped pushing anything to statsd (!).

I think it is related to nginx processing phases. zebrafishlabs/nginx-statsd does do logging in the last, log phase while content_by_lua_file is processed in the content phase and ngx.redirect's that my scripts use documentation states that it "(...) terminates the current request's processing and never returns." but proxy_pass is also in the content phase and statsd directives were run when I used them together in nginx...

1. Can you help me in this specific problem?

2. Do you have any success using zebrafishlabs/nginx-statsd with openresty? How do you do that?

PS I already thought of using lonelyplanet/openresty-statsd and it would probably be a working workaround but I would have to move all my statsd usage inside my script which I do not want to keep them clean.

UPDATE: lonelyplanet/openresty-statsd way also didn't work!?

Greg Dubicki
  • 1,191
  • 1
  • 14
  • 30

1 Answers1

0

In the end I made a workaround - started writing access logs to a file, analyze them by logstash and its statsd output plugin. It works.

0xC0000022L
  • 1,456
  • 2
  • 20
  • 41
Greg Dubicki
  • 1,191
  • 1
  • 14
  • 30