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.