hege 发表于 2018-10-27 14:53:01

fluentd +mongodb tomcat日志的搜集

  1.日志条目说明
  收集的日志有效内容如下
  ⑴访问来源IP
  ⑵访问的页面
  ⑶访问返回状态
  ⑷访问页面的大小
  ⑸访问时间
  ⑹访问浏览器的类型版本和系统类型等
  例子192.168.0.1 - - "GET /test.jsp HTTP/1.1" 200 204 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3)"
  搜集到mongodb 后的json 格式日志
  { "_id" : ObjectId("507e12de6e12474ee7000014"), "host" : "192.168.0.1", "user" : "-", "method" : "GET", "path" : "/jeep.jsp", "code" : "404", "size" : "979", "time" : ISODate("2012-10-17T01:21:38Z") }
  2.应用服务器tomcat服务 server.xml日志格式的修改
  日志搜集的时候tomcat 的server.xml 的模板
  把以下的注释 () 去掉
  
  改为

    prefix="t_uu_access_" suffix="log" pattern="combined"   rotatable="false"resolveHosts="true"/>
  prefix 中的参数是:t_项目的域名主体_access,例如esn.uu.com.cn,prefix 值设定为prefix="t_uu_access_"
  其中t 代表的是tomcat有别与Apache 和nginx
  参数说明

  Valve>  prefix:规定日志文件的前缀,即日志文件的名字
  suffix :规定日志文件的后缀,即日志文件的文件格式
  pattern(模式),pattern的两个值区别如下:
  common 的值: %h %l %u %t %r %s %b
  combined 的值: %h %l %u %t %r %s %b %{Referer}i %{User-Agent}i
  注:%a - Remote IP address
  %A - Local IP address
  %b - Bytes sent, excluding HTTP headers, or '-' if zero
  %B - Bytes sent, excluding HTTP headers
  %h - Remote host name (or IP address if resolveHosts is false)
  %H - Request protocol

  %l - Remote logical username from>  %m - Request method (GET, POST, etc.)
  %p - Local port on which this request was received
  %q - Query string (prepended with a '?' if it exists)
  %r - First line of the request (method and request URI)
  %s - HTTP status code of the response

  %S - User session>  %t - Date and time, in Common Log Format
  %u - Remote user that was authenticated (if any), else '-'
  %U - Requested URL path
  %v - Local server name
  %D - Time taken to process the request, in millis
  %T - Time taken to process the request, in seconds
  %I - current request thread name (can compare later with stacktraces)
  rotatable:决定日志是否轮巡
  true :轮巡,并把时间加入日志名中
  false:不轮巡。日志记录一直保存在同一个文件中
  resolveHosts:决定是否把远程的主机ip 通过DNS 查找返回主机名
  true : 返回主机名,
  false:不去查找
  注:查不到以“-”代替
  fileDateFormat:决定轮巡的日志名字追加的时间格式,以及通过时间格式确定轮巡的周期即日志写
  到新日志文件的周期。yyyy-MM-dd.HH   把值设定前文,是每个小时产生新的日志文件。不写此项,
  系统默认是每天轮巡。
  其他参数详见:http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html
  修改完要重启tomcat服务
  3.在fluentd 的收集端
  vim /etc/td-agent/td-agent.conf
  
  type forward
  port 24224
  bind 0.0.0.0
                          :source对 一个
              :match 对有多个,一个tomcat项目一个match 对
  #type file
  ##path /var/log/fluentd/access_log
  typemongo
  database apache                  :database 后指定mongodb 的数据库名线上确定为weblogs
  collection access                  :collection 后指定的是weblogs 库中存该项目tomcat日志的表名,即tomcat的日志名
  host 192.168.0.110               :指定mongodb 数据库的ip 线上环境
  port 27017                           :mongodb 的开放端口
  ignore_invalid_record true
  buffer_chunk_limit 5M
  flush_interval 60s
  
  注意:要搜集的日志的source 和match 对,其他的source 和match 对用注释掉
  4.web 应用端的td-agent 的配置文件说明
  
  type tail
  path /var/log/httpd/access_log      :指定所要收集的日志的全路径
  format apache
  tag    apache.access                        :指定所要搜集的日志的种类例如 nginx.accesstomcat.access ,
  
                          :指定匹配日志的类型这里的前缀和tag中的前缀一直
  type forward
  send_timeout 60s
  recover_wait 10s
  heartbeat_interval 1s
  phi_threshold 8
  hard_timeout 60s
                  :server对指定收集端的信息
  host 192.168.0.111:搜集端 的ip
  port 24224;         :搜集端开放的端口
  weight 60               :发送权重,可以有收集端由多个实现负载均衡,这里可以有多个server对
  
  
  注意:这里一个项目日志需要一个source对和一个match 对。

页: [1]
查看完整版本: fluentd +mongodb tomcat日志的搜集