3

I want to use GoAccess with Haproxy which works as reverse proxy and load balancer.

My goal is to create a custom log format which will be looking exactly like apache2 (compatible with default goaccess settings).

so far I did

capture request header Referrer len 64

capture request header Content-Length len 10

capture request header User-Agent len 64

log-format %si:%sp\ %ci\ -\ -\ [%t]\ "%r"\ %ST\ %B\ "%%Referrer"\ "%%User-Agent"

My haproxy version is HA-Proxy version 1.5.14 2015/07/02

I dont know how to extract referrer and user agent from captured request. I cant find anything usefull about Custom Log Format in manual.

EDIT

I figure out %hrl is a string list of the captured request headers. Is it possible to extract values by key or index?

4

I solved this by creating my own log format:

GoAccess

time-format %H:%M:%S

date-format %d/%b/%Y

log-format %^ %^ %^ %^ %^ %^ %h [%d:%t.%^] "%r" %s %b "{%R|%u}"

# %^ - skipped token
# %h - user ip
# %d - date-format
# %t - time-format
# %r - request e.g. GET /something
# %s - server status code
# %b - data response length
# %R - referer - very important if you want to know where your users come from
# %u - user agent

# There is so many skipped tokens because my haproxy put some extra information in every line or rsyslog(?)
# Sample line:
#
# Mar 22 09:09:06 server haproxy[PID]: 10.60.10.50:80 1.2.3.4 [22/Mar/2016:09:08:56.989] "POST /UIDL/?v-uiId=0 HTTP/1.1" 200 334 "{https://www.referer.com/|Mozilla/5.0 (Linux; Android 4.4.4; GT-I9060I Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Saf}"

Haproxy

capture request header Referer len 128
capture request header User-Agent len 128

log-format %si:%sp\ %ci\ [%t]\ "%r"\ %ST\ %B\ "%hr"

# %si - your server ip - very usefull if you have multiple application
# %sp - your server port
# %ci - user ip
# %t  - datetime in haproxy format
# %r  - request
# %ST - status code
# %B  - data reponse length
# %hr - captured headers separated by "|" (Referer|User-Agent)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.