Re: Status module – cache expiration, invalidation & poisoning.

António P. P. Almeida appa at
Sun Oct 14 21:12:33 UTC 2012

On 14 Out 2012 21h06 CEST, quintinpar at wrote:

> Hi Antonio,
> Can you help me a bit more? I have never written in lua
> Say for every hit I want to hit a rrd proxy like this
> echo "$location_url:1" | nc -w 1 -u 8125

This is not the ideal option because AFAIK (agentzh can chime in to
clarify things) the adding of the data to RRDtool will "hang" your

Ideally you should have a "frontend" location that issues two
subrequests one to write to RRDtool and another to get the response. I
don't think that in this particular case it will be dramatic. Try it
and see if you can live with it.

> how do I go about doing this in lua?


location /whatever-is-your-location {
    header_filter_by_lua '
        if ngx.var.upstream_cache_status == "HIT" and os.execute("echo " .. ngx.var.location_url .. ":1 | nc -w 1 -u 8125") == 0 then
            ngx.header["X-RRDtool"] = "YES"  

This adds a header X-RRDtool if successfull. I stress that this is not
the most performant way to do this. The Lua module can create sockets,
so the best option would be to use that facility and get rid of netcat

This is more of a hack than aything else. Perhaps is performant enough
for your application.

--- appa

More information about the nginx mailing list