Haproxy Json日志格式配置

 

通过日志工作分析日志时,非json日志分析起来比较麻烦。通过以下的配置,可以让生成的日志为json

   

log-format {"haproxy_clientIP":"%ci","haproxy_clientPort":"%cp","haproxy_dateTime":"%t","haproxy_frontendNameTransport":"%ft","haproxy_backend":"%b","haproxy_serverName":"%s","haproxy_Tw":"%Tw","haproxy_Tc":"%Tc","haproxy_Tt":"%Tt","haproxy_bytesRead":"%B","haproxy_terminationState":"%ts","haproxy_actconn":%ac,"haproxy_FrontendCurrentConn":%fc,"haproxy_backendCurrentConn":%bc,"haproxy_serverConcurrentConn":%sc,"haproxy_retries":%rc,"haproxy_srvQueue":%sq,"haproxy_backendQueue":%bq,"haproxy_backendSourceIP":"%bi","haproxy_backendSourcePort":"%bp","http_request":%r,"request_headers":"%hrl","response_headers":"%hsl","status_code":"%ST"}

   

   

   

   

   

配置实例:

  

# Global settings

  

#---------------------------------------------------------------------

  

global

  

log 127.0.0.1 local2

  

log-send-hostname

  

chroot /var/lib/haproxy

  

pidfile /var/run/haproxy.pid

  

maxconn 30000

  

user haproxy

  

group haproxy

  

daemon

  

# turn on stats unix socket

  

stats socket /var/lib/haproxy/stats

  

#---------------------------------------------------------------------

  

# common defaults that all the 'listen' and 'backend' sections will

  

# use if not designated in their block

  

#---------------------------------------------------------------------

  

defaults

  

mode http

  

log global

  

option httplog

  

option dontlognull

  

option http-server-close

  

option forwardfor except 127.0.0.0/8

  

option redispatch

  

retries 3

  

timeout http-request 10s

  

timeout queue 1m

  

timeout connect 10s

  

timeout client 1m

  

timeout server 1m

  

timeout http-keep-alive 10s

  

timeout check 10s

  

maxconn 50000

  

#---------------------------------------------------------------------

  

#---------------------------------------------------------------------

  

listen myapp1 :22222

  

mode tcp

  

option tcplog

  

log-format {"haproxy_clientIP":"%ci","haproxy_clientPort":"%cp","haproxy_dateTime":"%t","haproxy_frontendNameTransport":"%ft","haproxy_backend":"%b","haproxy_serverName":"%s","haproxy_Tw":"%Tw","haproxy_Tc":"%Tc","haproxy_Tt":"%Tt","haproxy_bytesRead":"%B","haproxy_terminationState":"%ts","haproxy_actconn":%ac,"haproxy_FrontendCurrentConn":%fc,"haproxy_backendCurrentConn":%bc,"haproxy_serverConcurrentConn":%sc,"haproxy_retries":%rc,"haproxy_srvQueue":%sq,"haproxy_backendQueue":%bq,"haproxy_backendSourceIP":"%bi","haproxy_backendSourcePort":"%bp"}

  

option logasap

  

balance leastconn

  

server server1 xx.xx.xx.xx:22222

  

server server2 xx.xx.xx.xx:22222

  

server server3 xx.xx.xx.xx:22222

  

listen myapp2 :22201

  

mode tcp

  

option tcplog

  

log-format {"haproxy_clientIP":"%ci","haproxy_clientPort":"%cp","haproxy_dateTime":"%t","haproxy_frontendNameTransport":"%ft","haproxy_backend":"%b","haproxy_serverName":"%s","haproxy_Tw":"%Tw","haproxy_Tc":"%Tc","haproxy_Tt":"%Tt","haproxy_bytesRead":"%B","haproxy_terminationState":"%ts","haproxy_actconn":%ac,"haproxy_FrontendCurrentConn":%fc,"haproxy_backendCurrentConn":%bc,"haproxy_serverConcurrentConn":%sc,"haproxy_retries":%rc,"haproxy_srvQueue":%sq,"haproxy_backendQueue":%bq,"haproxy_backendSourceIP":"%bi","haproxy_backendSourcePort":"%bp"}

  

option logasap

  

balance leastconn

  

server server1 xx.xx.xx.xx:22201

  

server server2 xx.xx.xx.xx:22201

  

server server3 xx.xx.xx.xx:22201

  

# Interface Web

  

listen stats *:80

  

stats enable

  

stats uri /

  

stats refresh 5s

  

stats hide-version

   

来自 <https://github.com/jothoma1/graylog-contentpack-haproxy/blob/master/sample-haproxy.cfg>

   

   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值