Logstash Grok 导入 Apache 访问日志文件 数据丰富

发布于 2025-02-27 23:24:34 字数 2241 浏览 1 评论 0

测试数据

apache_access.log

216.244.66.246 - - [30/Apr/2017:04:28:11 +0000] "GET /docs/triton/pages.html HTTP/1.1" 200 5639 "-" "Mozilla/5.0 (compatible; DotBot/1.1; http://www.opensiteexplorer.org/dotbot, help@moz.com)"
199.21.99.207 - - [30/Apr/2017:04:29:44 +0000] "GET /docs/triton/class_triton_1_1_wind_fetch-members.html HTTP/1.1" 200 1845 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
199.21.99.207 - - [30/Apr/2017:04:29:57 +0000] "GET /docs/triton/class_triton_1_1_breaking_waves_parameters-members.html HTTP/1.1" 200 1967 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
100.43.90.9 - - [30/Apr/2017:04:30:13 +0000] "GET /docs/html/functions_rela.html HTTP/1.1" 200 882 "-" "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
217.182.132.36 - - [30/Apr/2017:04:30:31 +0000] "GET /2012/08/sundog-software-featured-in-august-2012-issue-of-develop/ HTTP/1.1" 200 14326 "-" "Mozilla/5.0 (compatible; AhrefsBot/5.2; +http://ahrefs.com/robot/)"
54.210.20.202 - - [30/Apr/2017:04:30:58 +0000] "POST /wp-cron.php?doing_wp_cron=1493526658.6017329692840576171875 HTTP/1.1" 200 - "http://sundog-soft.com/wp-cron.php?doing_wp_cron=1493526658.6017329692840576171875" "WordPress/4.7.4; http://sundog-soft.com"

Logstash 配置文件

logstash.conf

input {
  file {
    path => "/Users/jasonwu/WorkSpace/learn/Elasticsearch/apache_access.log"
    start_position => "beginning"
    sincedb_path => "/Users/jasonwu/.Trash/sincedb.trash"
  }
}

filter {
  grok {
    match => {
      "message" => ["%{COMBINEDAPACHELOG}"]
    }
  }

  useragent {
    source => "agent"
    target => "agent"
  }

  geoip {
    source => "clientip"
    target => "geoip"
  }

  mutate {
    add_field => {
      "read_timestamp" => "%{@timestamp}"
    }

    remove_field => ["path", "@version", "message", "@timestamp", "host"]
  }
}

output {
  stdout {}

  elasticsearch {
    hosts => ["localhost:9200"]
    index => "logs"
  }
}

执行 Logstash 导入 Elasticsearch

$ bin/logstash -f /Users/jasonwu/WorkSpace/learn/Elasticsearch/logstash.conf

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

漆黑的白昼

暂无简介

文章
评论
27 人气
更多

推荐作者

冰之心

文章 0 评论 0

貪欢

文章 0 评论 0

guowei007

文章 0 评论 0

大海や

文章 0 评论 0

1KUPGZrJCxEwZ

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文