Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log cache hit or miss in log file #121

Closed
akash-rp opened this issue Dec 8, 2021 · 2 comments
Closed

Log cache hit or miss in log file #121

akash-rp opened this issue Dec 8, 2021 · 2 comments

Comments

@akash-rp
Copy link

akash-rp commented Dec 8, 2021

Hi, Is their any way to log cache hit or miss in the log file

@jiangwenyuan
Copy link
Owner

Yes

By enabling haproxy log, you can tell a hit or miss by check backend:

Dec  9 23:54:51 localhost haproxy[1487]: 127.0.0.1:54105 [09/Dec/2021:23:54:51.476] fe-cache be-cache/s1 0/0/0/1/2 200 818 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"                                                                           
Dec  9 23:54:52 localhost haproxy[1487]: 127.0.0.1:54109 [09/Dec/2021:23:54:52.161] fe-cache be-cache/<NUSTER.CACHE.ENGINE> 0/0/0/0/0 200 818 - - ---- 1/1/0/0/0 0/0 "GET / HTTP/1.1"                                                        

So if the backend is <NUSTER.CACHE.ENGINE>, it's a hit.

And you can log hit header if you wish

http-response add-header hit yes if { nuster.cache.hit }                                          
declare capture response len 20                                                                   
http-response capture res.hdr(hit) id 0                                                           
                                                                                                    
log-format "|%[capture.res.hdr(0)]| %ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"                                

And you will get logs like

Dec 10 00:04:56 localhost haproxy[1572]: |yes| 127.0.0.1:54149 [10/Dec/2021:00:04:56.654] fe-cache be-cache/<NUSTER.CACHE.ENGINE> 0/0/0/0/0 200 818 - - ---- 1/1/0/0/0 0/0 {yes} "GET /? HTTP/1.1"                                           

@akash-rp
Copy link
Author

Thank You

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants