counters in nginx

Roman Vasilyev roman at anchorfree.com
Thu Feb 10 05:06:20 MSK 2011


Hi,

I need to realize event counters in nginx.
So I've planned to create command like "counter".
And have something similar to HttpLimit(Zone/Req)Module,
so my config should looks like:
http {
   counter_zone   one  $binary_remote_addr  10m;
  ...
   server {
...
     location / {
       count one $my_event; #( $my_event can be 0 or 1 )
     }
   }
}
and have extra location like
location /my_one_stats { # will give stats to external script for 
specific argument;
   counter_handler one $args_one;
}

location /my_one_stats_reset { # will reset stats for specific argument;
   counter_reset one $args_one;
}


In this case to be insured that my counter working in final phase I have 
to register this handler in NGX_HTTP_LOG_PHASE phase, otherwise I 
wouldn't know for sure that event is done.
But if I'll register it on init like:
  h = ngx_array_push(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers);
my handler will be called after HttpLogModule, so if I'll try to log 
counter only previous value will be logged.

So my question:
1) May be exists more effective way to realize it, or it already realized?
2) What the best way to register handler before HttpLogModule but in 
NGX_HTTP_LOG_PHASE?

Regards



More information about the nginx mailing list