I am new to ha-proxy and trying to push the logs to elastic search using filebeat. As filebeat only takes json format and I am not getting a way to configure ha-proxy to output the logs in json format, which includes both success and error cases.
I have tried the below log format in conf file -
log-format '{"host":"%H","ident":"haproxy","pid":%pid,"time":"%Tl","haproxy":{"conn":{"act":%ac,"fe":%fc,"be":%bc,"srv":%sc},"queue":{"backend":%bq,"srv":%sq},"time":{"tq":%Tq,"tw":%Tw,"tc":%Tc,"tr":%Tr,"tt":%Tt},"termination_state":"%tsc","retries":%rc,"network":{"client_ip":"%ci","client_port":%cp,"frontend_ip":"%fi","frontend_port":%fp},"ssl":{"version":"%sslv","ciphers":"%sslc"},"request":{"method":"%HM","uri":"%[capture.req.uri,json(utf8s)]","protocol":"%HV","header":{"host":"%[capture.req.hdr(0),json(utf8s)]","xforwardfor":"%[capture.req.hdr(1),json(utf8s)]","referer":"%[capture.req.hdr(2),json(utf8s)]"}},"name":{"backend":"%b","frontend":"%ft","server":"%s"},"response":{"status_code":%ST,"header":{"xrequestid":"%[capture.res.hdr(0),json(utf8s)]"}},"bytes":{"uploaded":%U,"read":%B}}}'
And now the json logs are written along with regular logs in same old log file. But a pule json log file is needed for the filebeat and in separate file.
Any leads would be helpful.
Thanks.
Filebeat is pretty fine with JSON logs or plain text logs. The opposite is even mainly the case for infrastructure logs like server or syslog messages.
I addition, filebeat provides you with a dedicated ha-proxy module, which will simplify your task a lot. Please see the docs, there should be anything you need to setup filebeat for HA-Proxy.
Have Fun!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With