通过日志工作分析日志时,非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#---------------------------------------------------------------------globallog 127.0.0.1 local2log-send-hostnamechroot /var/lib/haproxypidfile /var/run/haproxy.pidmaxconn 30000user haproxygroup haproxydaemon# turn on stats unix socketstats socket /var/lib/haproxy/stats#---------------------------------------------------------------------# common defaults that all the 'listen' and 'backend' sections will# use if not designated in their block#---------------------------------------------------------------------defaultsmode httplog globaloption httplogoption dontlognulloption http-server-closeoption forwardfor except 127.0.0.0/8option redispatchretries 3timeout http-request 10stimeout queue 1mtimeout connect 10stimeout client 1mtimeout server 1mtimeout http-keep-alive 10stimeout check 10smaxconn 50000#---------------------------------------------------------------------#---------------------------------------------------------------------listen myapp1 :22222mode tcpoption tcploglog-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 logasapbalance leastconnserver server1 xx.xx.xx.xx:22222server server2 xx.xx.xx.xx:22222server server3 xx.xx.xx.xx:22222listen myapp2 :22201mode tcpoption tcploglog-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 logasapbalance leastconnserver server1 xx.xx.xx.xx:22201server server2 xx.xx.xx.xx:22201server server3 xx.xx.xx.xx:22201# Interface Weblisten stats *:80stats enablestats uri /stats refresh 5sstats hide-version

转载于:https://www.cnblogs.com/breezey/p/8810170.html

HAproxy Json日志格式配置相关推荐

  1. nginx-ingress设置日志格式-配置转发真实ip-超时参数配置-会话保持参数

    nginx-ingress设置日志格式-配置转发真实ip-白名单限制 参考官方文档 nginx-ingress官方文档 修改nginx-ingrss的configmap配置文件 apiVersion: ...

  2. Nginx配置-日志格式配置

    Nginx配置-日志格式配置 一.默认的日志格式 二.我使用的日志格式 三.参数 四.测试效果 五一上线了一个小的预约程序,配置通过Nginx进行访问入口,默认的日志是没有请求时间的,因此需要配置一下 ...

  3. @slf4j日志格式配置

    使用@Slf4j注解配置日志: 步骤: 在pom.xml中添加lombok; 使用@Slf4j注解: 默认可以使用log.error().log.info().log.debug()等输出: 设置日志 ...

  4. nginx日志格式配置

    nginx作为我们IT中的首选反向代理神器,有时候我们有必要查看nginx中的日志的,但是我们对nginx的日志格式不是很了解怎么办呢?这样以来也是看不懂的. nginx日志 nginx的日志分两种一 ...

  5. Nginx日志格式配置-转载

    最近项目使用到了nginx的反向代理,配置过程中查询了一些nginx日志配置的问题,便于自己学习查询 nginx服务器日志相关指令主要有两条,一条是log_format,用来设置日志格式,另外一条是a ...

  6. Logback Pattern 日志格式配置

    Logback日志配置示例 <appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppe ...

  7. nginx日志输出配置json格式

    nginx日志输出配置json格式 nginx服务器日志相关指令主要有两条:一条是log_format,用来设置日志格式:另外一条是access_log,用来指定日志文件的存放路径.格式和缓存大小. ...

  8. nginx日志格式及自定义日志配置

    1.nginx的log日志分为access log 和 error log 其中access log 记录了哪些用户,哪些页面以及用户浏览器.ip和其他的访问信息:error log 则是记录服务器错 ...

  9. haproxy开启日志功能

    转载请注明出处:http://www.cnblogs.com/gaojiang/p/6727223.html 由于数据分析的需要,我们必须打开Haproxy日志,并记录相关的503错误信息进行汇总统计 ...

最新文章

  1. php session 为空,thinkphp无法登陆,session跨页后值为空
  2. (数据结构与算法)数组和单链表实现栈的基本操作
  3. vue中form表单支持回车键提交踩坑
  4. http协议实现web服务器,http协议实现web服务器
  5. H.264解码器中CAVLC码表查找算法的分析与优化
  6. iOS12.3正式版发布 iOS13亮相进入倒计时
  7. 新浪下拉菜单(js原生版本)
  8. Visual Studio 2005 开发 Silverlight 1.0
  9. Codeforces 600E. Lomsat gelral(Dsu on tree学习)
  10. VB / VS 多语言软件设计
  11. Redis-03-Redis集群的搭建
  12. Unity:一键移除所有预制体上的Missing脚本
  13. HNUCM-1435 最大最小值(分治法)
  14. 《C专家编程》之 内存泄漏
  15. 游戏制作之路:游戏引擎选择、Mac下和Windows下UnrealEngine 4体验对比、文档及其他 -- 前几天我说要学做游戏的流程...
  16. Angular + PrimeNG 安装配置
  17. 图形商标近似检索-知擎者的 Milvus 实践
  18. 基于A*算法的迷宫游戏
  19. 第1讲 几种密码技术的简要介绍——《图解密码技术》
  20. 我怎么就被一张照片出卖了?可怕!

热门文章

  1. Java读写二进制文件
  2. (Spinner) android中Spinner的使用
  3. mysql select 使用_mysql select简单用法
  4. android手机连接无线路由器上网设置,怎样用手机设置无线路由器上网?
  5. linux下运行lua,linux下配置Lua运行环境
  6. c语言编译及下载环境变量,windows 下使用g++ 编译器-Go语言中文社区
  7. kettle 查询数据库写入文件_怎么连接数据库-详解如何用kettle连接mysql数据库并导出sql查询结果...
  8. vbmsgbox引用变量_vba中MsgBox的参数及用法
  9. hubliderx如选择相同单词_高考英语,十六种高效单词记忆法,建议人手一份!
  10. js aes加密_nodejs中使用Crypto-JS对图片进行加解密