{"id":229,"date":"2015-03-11T21:50:08","date_gmt":"2015-03-12T03:50:08","guid":{"rendered":"https:\/\/www.jumpcloud.com\/engineering-blog\/?p=229"},"modified":"2021-10-08T13:21:27","modified_gmt":"2021-10-08T17:21:27","slug":"custom-logging-per-backend-in-haproxy","status":"publish","type":"post","link":"https:\/\/jumpcloud.com\/blog\/custom-logging-per-backend-in-haproxy","title":{"rendered":"Custom logging per backend in HAProxy"},"content":{"rendered":"\n
HAProxy has good configurable logging.<\/p>\n\n\n\n
I have a proxy with two backends, routed differently based on the port they’re using.<\/p>\n\n\n\n
#———————————————————————\n# http frontend\n#———————————————————————\nfrontend http_frontend\n bind *:444\n default_backend http_backend\n\n#———————————————————————\n# nssocket frontend\n#———————————————————————\nfrontend nssocket_frontend\n bind *:443\n default_backend nssocket_backend\n<\/pre>\n\n\n\nThe issue is that ‘nssocket’ traffic is way higher than the http traffic. It’s also less useful information to me, since I care about that traffic less. I’d like to have it be less verbose in my logs, but still sensitive enough to let me know if there’s trouble.<\/p>\n\n\n\n
nssocket_frontend nssocket_backend\/as11 1\/0\/15 1244 — 638\/4\/4\/1\/0 0\/0\nhttp_frontend http_backend\/as8 1\/0\/5310 1261 — 639\/633\/633\/123\/0 0\/0\nnssocket_frontend nssocket_backend\/as8 1\/0\/142 1244 — 638\/5\/5\/1\/0 0\/0\nnssocket_frontend nssocket_backend\/as11 1\/0\/12 1244 — 637\/4\/4\/1\/0 0\/0\nnssocket_frontend nssocket_backend\/as11 1\/0\/13 1244 — 637\/4\/4\/1\/0 0\/0\nnssocket_frontend nssocket_backend\/as11 1\/0\/168 1244 — 637\/4\/4\/1\/0 0\/0\nnssocket_frontend nssocket_backend\/as11 1\/0\/12 1244 — 636\/3\/3\/0\/0 0\/0\nnssocket_frontend nssocket_backend\/as11 1\/0\/14 1244 — 638\/5\/5\/1\/0 0\/0\nnssocket_frontend nssocket_backend\/as8 1\/0\/163 1244 — 640\/7\/7\/1\/0 0\/0\nnssocket_frontend nssocket_backend\/as11 1\/0\/16 1244 — 639\/6\/6\/2\/0 0\/0\nnssocket_frontend nssocket_backend\/as11 1\/0\/14 1244 — 640\/7\/7\/3\/0 0\/0\n<\/pre>\n\n\n\nBasically, I want different logging in HAProxy based on the frontend. The noisy nssocket is just distracting.<\/p>\n\n\n\n
Right now, all logging is being defined via the ‘global’ setting.<\/p>\n\n\n\n
global\n log 127.0.0.1 local2 debug\n<\/pre>\n\n\n\nTo make this HAProxy logging discriminate per frontend, I override the log settings in each frontend section.<\/p>\n\n\n\n
#———————————————————————\n# http frontend\n#———————————————————————\nfrontend http_frontend\n bind *:444\n default_backend http_backend\n log 127.0.0.1 local2 debug\n\n#———————————————————————\n# nssocket frontend\n#———————————————————————\nfrontend nssocket_frontend\n bind *:443\n default_backend nssocket_backend\n log 127.0.0.1 local2 warning\n<\/pre>\n\n\n\nNow, the logs give me a much more valuable insight into the incoming traffic that I care about, highlighting only the http traffic that matters to me.<\/p>\n\n\n\n
http_frontend http_backend\/as9 1\/0\/1103 1479 — 1893\/1887\/1887\/354\/0 0\/0\nhttp_frontend http_backend\/as12 1\/14\/6256 1261 — 1897\/1891\/1891\/434\/0 0\/0\nhttp_frontend http_backend\/as11 1\/0\/6379 1261 — 1917\/1911\/1911\/351\/0 0\/0\nhttp_frontend http_backend\/as8 1\/0\/6115 1261 — 1918\/1911\/1911\/347\/0 0\/0\nhttp_frontend http_backend\/as11 1\/0\/1297 1479 — 1921\/1914\/1914\/350\/0 0\/0\n<\/pre>\n","protected":false},"excerpt":{"rendered":"With custom logging per backend in HAProxy, the logs highlight only the valuable http traffic that matters to your organization.<\/p>\n","protected":false},"author":30,"featured_media":232,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_oasis_is_in_workflow":0,"_oasis_original":0,"_oasis_task_priority":"","inline_featured_image":false,"footnotes":""},"categories":[42],"tags":[],"collection":[],"platform":[],"funnel_stage":[3014],"coauthors":[],"acf":[],"yoast_head":"\n
Custom logging per backend in HAProxy - JumpCloud<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n\n\t\n\t\n\t\n