Haproxy Json日志格式配置
2017-09-12 14:56
976 查看
通过日志工作分析日志时,非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>
相关文章推荐
- HAproxy Json日志格式配置
- nginx中用JSON格式记录日志的配置示例
- Logstash收集json格式日志文件如何写配置文件
- WebApi关于配置全局返回Json数据格式时间以及命名小写
- haproxy打印日志配置
- WIN7配置IIS支持.json格式文件(转)
- 配置Haproxy增加日志记录功能
- tomcat accesslog日志配置及格式说明
- 【框架整合】Maven-SpringMVC3.X+Spring3.X+MyBatis3-日志、JSON解析、表关联查询等均已配置好
- 成功配置TOMCAT的LOG4J日志系统,格式:HTML+每天以YYYY-MM-DD.LOG命名的日志文件
- 修改CDH进程NN、DN日志输出为JSON格式
- haproxy 配置日志
- haproxy高可用日志记录配置文件
- nginx日志格式及自定义日志配置
- cxf-rest 配置JSonProvider 来定制JSON的转换格式
- haproxy的日志配置
- Android Studio 配置 toString( ) 模板,定制 JSON 格式字串的步骤
- 配置iis支持.json格式的文件
- 一、WIN7下EasyUI环境IIS配置支持.json格式的文件
- convention-plugin使用Annotation配置JSON格式的Action