cat /data/tomcat/conf/server.xml

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s" />
<Context docBase="/data/webserver/" path="/" reloadable="false" />

输出格式如下:

172.16.200.16 - - [21/Oct/2016:16:55:03 +0800] "GET /static/My97DatePicker/skin/WdatePicker.css HTTP/1.1" 304

  1. input {
  2. file {
  3. path => "/data/tomcat/logs/localhost_access_log.2016-10-24.txt"
  4. start_position => "beginning"
  5. type => "tomcat_access"
  6. }
  7. }
  8.  
  9. filter {
  10. if [type] == "tomcat_access" {
  11. grok{
  12. match => { "message" => "%{IPORHOST:clientip} %{USER:ident} %{USER:auth} \[%{HTTPDATE:timestamp}\] \"(?:%{WORD:verb} %{URIPATHPARAM:request}(?: HTTP/%{NUMBER:httpversion})?|-)\" %{NUMBER:response}"}
  13. }
  14. }
  15. }
  16.  
  17. output {
  18. if [type] == "tomcat_access" {
  19. kafka {
  20. bootstrap_servers => "kafka1:9092,kafka2:9092,kafka3:9092"
  21. topic_id => "tomcat_access.log"
  22. compression_type => "snappy"
  23. }
  24. }
  25. }

logstash 服务器端

  1. input {
  2. if [type] == "haproxy_http" {
  3. kafka {
  4. zk_connect => "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181"
  5. topic_id => "haproxy_http.log"
  6. reset_beginning => false
  7. consumer_threads =>
  8. decorate_events => true
  9. }
  10. } else if [type] == "haproxy_tcp" {
  11. kafka {
  12. zk_connect => "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181"
  13. topic_id => "haproxy_tcp.log"
  14. reset_beginning => false
  15. consumer_threads =>
  16. decorate_events => true
  17. }
  18. } else if [type] == "tomcat_access" {
  19. kafka {
  20. zk_connect => "zookeeper1:2181,zookeeper2:2181,zookeeper3:2181"
  21. topic_id => "tomcat_access.log"
  22. reset_beginning => false
  23. consumer_threads =>
  24. decorate_events => true
  25. }
  26. }
  27. }
  28.  
  29. output {
  30. if [type] == "haproxy_http" {
  31. elasticsearch {
  32. hosts => ["es1:9200","es2:9200","es3:9200"]
  33. manage_template => true
  34. index => "logstash-haproxy-http.log-%{+YYYY-MM-dd}"
  35. }
  36. }
  37. if [type] == "haproxy_tcp" {
  38. elasticsearch {
  39. hosts => ["es1:9200","es2:9200","es3:9200"]
  40. manage_template => true
  41. index => "logstash-haproxy-tcp.log-%{+YYYY-MM-dd}"
  42. }
  43. }
  44. if [type] == "tomcat_access" {
  45. elasticsearch {
  46. hosts => ["es1:9200","es2:9200","es3:9200"]
  47. manage_template => true
  48. index => "logstash-tomcat_access.log-%{+YYYY-MM-dd}"
  49. }
  50. }
  51.  
  52. }
  1.  

tomcat 格式化输出到kafka的更多相关文章

  1. tomcat及nginx相关,格式化输出,配置及日志解析

    1.https://www.cnblogs.com/jingmoxukong/p/8258837.html?utm_source=gold_browser_extension       Tomcat ...

  2. Python自动化运维之4、格式化输出、文件对象

    Python格式化输出: Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存.[P ...

  3. Golang:将日志以Json格式输出到Kafka

    在上一篇文章中我实现了一个支持Debug.Info.Error等多个级别的日志库,并将日志写到了磁盘文件中,代码比较简单,适合练手.有兴趣的可以通过这个链接前往:https://github.com/ ...

  4. python的print函数的格式化输出

    使用print函数的时候,可以像C一样格式化输出,同时还支持参数化输出 print('%s' % ("CooMark")) print('整数|%d|' % (123)) prin ...

  5. python学习笔记(基础二:注释、用户输入、格式化输出)

    注释 单行:# 多行:上下各用3个连续单引号或双引号 3个引号除了多行注释,还可以打印多行 举例: msg = ''' name = "Alex Li" name2 = name ...

  6. cout 格式化输出

    一直习惯于C语言的printf函数来打印,突然有一天要用cout来打印,发现有点不适应. 原来cout也是有格式化输出的. 首先要引入头文件 #include<iostream> // 在 ...

  7. Python 格式化输出

    转载 今天写程序又记不清格式化输出细节了--= =索性整理一下. 注意: 与C/C++  不同的是这里括号后面不需要加' , '号. python print格式化输出. 1. 打印字符串 print ...

  8. Python格式化输出

    今天写程序又记不清格式化输出细节了……= =索性整理一下. python print格式化输出. 1. 打印字符串 print ("His name is %s"%("A ...

  9. Javascript实现格式化输出

    前两天看面试题,其中有一道要实现js的格式化输出,具体给出的是: Javascript实现格式化输出,比如输入999999999,输出为999,999,999 我的实现方式是 function for ...

随机推荐

  1. 【leetcode】Perfect Squares (#279)

    Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...

  2. [转]js 将图片连接转换称base64格式

    参考:http://blog.csdn.net/wyyfwm/article/details/45917255 我们把图像文件的内容直接写在了HTML 文件中,这样做的好处是,节省了一个HTTP 请求 ...

  3. ubuntu wifi连接不上或经常断网,重启就好

    问题1.知道wifi密码,驱动也有,可以点击连接,总是提示"连接断开,您现在处于离线状态". 1.打开终端"ctrl+alt+T" 2.输入: sudo vim ...

  4. activity 、window与view的关系(下)

    在activity的attacth方法中,通过policymanager 的makenewwindow来创建window 而window的具体实现是phonewindow 接下来通过setconten ...

  5. 服务器响应HTTP的类型ContentType大全

    ".*"="application/octet-stream" ".001"="application/x-001" & ...

  6. CentOS利用inotify+rsync实现文件同步

    1.环境部署 inotify-master 10.10.6.208 inotify-slave 10.10.6.149 2.两台服务器都安装rsync yum install -y rsync 3.i ...

  7. Codeforces Round #FF(255) DIV2

    A - DZY Loves Hash 水题,开辟一个数组即可 #include <iostream> #include <vector> #include <algori ...

  8. Main 程序的入口要做哪些事情

    Main 程序的入口要做哪些事: 1.从主类中实例化程序(UIApplication)对象 2.如果有委托的话,从给定的类实例化委托和设置程序(UIApplication) 的代理. 3.开启主事件的 ...

  9. H5开发中的问题总结

    最近公司做了一个出行日记的项目,里面的页面十多页,天天加班,做到吐血.总体来说,写页面的时候虽然是十多个页面,其实难度还是在每个页面的特效上.公司是易到用车,出行日记的页面在APP里有生成入口,有兴趣 ...

  10. 李洪强iOS经典面试题147-WebView与JS交互

    李洪强iOS经典面试题147-WebView与JS交互   WebView与JS交互 iOS中调用HTML 1. 加载网页 NSURL *url = [[NSBundle mainBundle] UR ...