kafka_elasticsearch.conf 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. input {
  2. kafka {
  3. codec => json{}
  4. bootstrap_servers => "kafka:9092"
  5. topics => ["nginx-access", "random", "apache"]
  6. client_id => "logstash_indexer_1"
  7. }
  8. }
  9. filter {
  10. if [type] == "nginx-access" {
  11. grok {
  12. match => [ "message" , "%{COMBINEDAPACHELOG}+%{GREEDYDATA:extra_fields}"]
  13. overwrite => [ "message" ]
  14. }
  15. mutate {
  16. convert => ["response", "integer"]
  17. convert => ["bytes", "integer"]
  18. convert => ["responsetime", "float"]
  19. }
  20. geoip {
  21. source => "clientip"
  22. target => "geoip"
  23. add_tag => [ "nginx-geoip" ]
  24. }
  25. date {
  26. match => [ "timestamp" , "dd/MMM/YYYY:HH:mm:ss Z" ]
  27. remove_field => [ "timestamp" ]
  28. }
  29. useragent {
  30. source => "agent"
  31. }
  32. }
  33. if [type] == "random" {
  34. grok {
  35. match => [ "message" , "(?<timestamp>%{YEAR}[./-]%{MONTHNUM}[./-]%{MONTHDAY}[- ]%{TIME}) %{NUMBER:pid} %{GREEDYDATA:filename} %{NUMBER:line} %{GREEDYDATA:logger} %{LOGLEVEL:severity} %{GREEDYDATA:quote}"]
  36. overwrite => [ "message" ]
  37. }
  38. date {
  39. match => [ "timestamp", "YYYY-MM-dd HH:mm:ss,SSS"]
  40. remove_field => [ "timestamp" ]
  41. }
  42. }
  43. if [type] == "apache" {
  44. grok {
  45. match => [ "message" , "%{COMBINEDAPACHELOG}"]
  46. overwrite => [ "message" ]
  47. }
  48. mutate {
  49. convert => ["response", "integer"]
  50. convert => ["bytes", "integer"]
  51. convert => ["responsetime", "float"]
  52. }
  53. geoip {
  54. source => "clientip"
  55. target => "geoip"
  56. add_tag => [ "apache-geoip" ]
  57. }
  58. date {
  59. match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ]
  60. remove_field => [ "timestamp" ]
  61. }
  62. }
  63. }
  64. output {
  65. if [type] == "nginx-access" {
  66. elasticsearch {
  67. hosts => ["elasticsearch:9200"]
  68. index => "nginx-%{+YYYYMM}"
  69. }
  70. stdout {
  71. codec => rubydebug
  72. }
  73. }
  74. if [type] == "random" {
  75. elasticsearch {
  76. hosts => ["elasticsearch:9200"]
  77. index => "random-%{+YYYYMM}"
  78. }
  79. stdout {
  80. codec => rubydebug
  81. }
  82. }
  83. if [type] == "apache" {
  84. elasticsearch {
  85. hosts => ["elasticsearch:9200"]
  86. index => "apache-%{+YYYYMM}"
  87. }
  88. stdout {
  89. codec => rubydebug
  90. }
  91. }
  92. }