Hi all, I have a website thats heavily cached or intended to be heavily cached via Nginx . But somehow looking at the page response time I feeling there is a very high eviction/invalidation rate. Now is there way I can look at the cache status in Nginx for different. I dont use the purge module. The only way I check cache status is through add_header X-Cache-Status $upstream_cache_status; I want to o/p the cache status to a RRD tool and look at the metrics. Is this possible?
on 2012-10-14 20:12
on 2012-10-14 20:33
On 14 Out 2012 20h11 CEST, quintinpar@gmail.com wrote: > > The only way I check cache status is through > > add_header X-Cache-Status $upstream_cache_status; > > I want to o/p the cache status to a RRD tool and look at the > metrics. > > Is this possible? With Lua shouldn't be that difficult. You just inspect the value of $upstream_cache_status. ngx.var.upstream_cache_status paired with http://wiki.nginx.org/HttpLuaModule#ngx.location.capture to use a specific location to write to RRDtool. Just an idea, --- appa
on 2012-10-14 21:07
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 host.com 8125 how do I go about doing this in lua?
on 2012-10-14 23:12
On 14 Out 2012 21h06 CEST, quintinpar@gmail.com 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 host.com 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 reply. 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? Try: 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 host.com 8125") == 0 then ngx.header["X-RRDtool"] = "YES" end '; } 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 IMO. This is more of a hack than aything else. Perhaps is performant enough for your application. YMMV, --- appa
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.