【问题标题】:Tag a message on the filebeat side to be able to filter on kibana ( HTTP response codes )在 filebeat 端标记一条消息,以便能够在 kibana 上过滤(HTTP 响应代码)
【发布时间】:2018-11-30 15:35:55
【问题描述】:

我有这个配置:

filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /var/log/messages
    - /var/log/secure
    - /var/log/audit/audit.log
    - /var/log/yum.log
    - /root/.bash_history
    - /var/log/neutron/*.log
    - /var/log/nova/*.log
    - /var/log/keystone/keystone.log
    - /var/log/httpd/error_log
    - /var/log/mariadb/mariadb.log
    - /var/log/glance/*.log
    - /var/log/rabbitmq/*.log
  ignore_older: 72h
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false
output.logstash:
  hosts: ["sdsds"]

如果日志包含以下模式,我想标记它: 消息:信息HTTP*200* 我想在 kibana 上创建一个查询以根据 http 响应代码标签进行过滤。我怎样才能创建这个?你能帮我用标签创建条件吗? 此响应代码位于 nova-api 和 neutron 服务器日志中。 而且我不想真正过滤掉日志,我想在弹性搜索中拥有一切,只想为这些日志添加标签。

更新:

我设法弄清楚了一些事情,但我不确定列出它的最佳方式是什么,因为我有很多响应代码:

filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /var/log/messages
    - /var/log/secure
    - /var/log/audit/audit.log
    - /var/log/yum.log
    - /root/.bash_history
    - /var/log/neutron/*.log
    - /var/log/keystone/keystone.log
    - /var/log/httpd/error_log
    - /var/log/mariadb/mariadb.log
    - /var/log/glance/*.log
    - /var/log/rabbitmq/*.log
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  include_lines: ["status: 200"]
  fields_under_root: true
  fields:
    httpresponsecode: 200
  ignore_older: 72h
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false
output.logstash:

我必须多次创建这 4 行?

filebeat.prospectors:
- type: log
  enabled: true
  paths:
    - /var/log/messages
    - /var/log/secure
    - /var/log/audit/audit.log
    - /var/log/yum.log
    - /root/.bash_history
    - /var/log/keystone/keystone.log
    - /var/log/neutron/*.log
    - /var/log/httpd/error_log
    - /var/log/mariadb/mariadb.log
    - /var/log/glance/*.log
    - /var/log/rabbitmq/*.log
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  fields_under_root: true
  include_lines: ["status: 200"]
  fields:
    httpresponsecode: 200
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  fields_under_root: true
  include_lines: ["status: 202"]
  fields:
    httpresponsecode: 202
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  fields_under_root: true
  include_lines: ["status: 204"]
  fields:
    httpresponsecode: 204
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  fields_under_root: true
  include_lines: ["status: 207"]
  fields:
    httpresponsecode: 207
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  fields_under_root: true
  include_lines: ["status: 403"]
  fields:
    httpresponsecode: 403
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  fields_under_root: true
  include_lines: ["status: 404"]
  fields:
    httpresponsecode: 404
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  fields_under_root: true
  include_lines: ["status: 500"]
  fields:
    httpresponsecode: 500
- type: log
  enabled: true
  paths:
    - /var/log/nova/*.log
  fields_under_root: true
  include_lines: ["HTTP 503"]
  fields:
    httpresponsecode: 503
  ignore_older: 72h
filebeat.config.modules:
  path: ${path.config}/modules.d/*.yml
  reload.enabled: false
output.logstash:
  hosts: [

对多个文件和多个代码执行此操作的最佳方法是什么?

更新2: 我的解决方案不起作用,一开始它正在发送,然后完全停止。 我希望你能帮助我。

【问题讨论】:

  • 我看到您正在通过 Logstash 流式传输您的日志,为什么不在 Logstash 过滤器中添加该标签?
  • 因为如果它只影响少量服务器,其他团队不想在索引器上应用过滤器:D
  • 请查看 filebeat (elastic.co/guide/en/beats/filebeat/master/…) 中的处理器,它使您能够“过滤和增强导出的数据”(elastic.co/guide/en/beats/filebeat/6.5/…)。也许这就是您正在寻找的(如果您能够定义适当的条件)。
  • 这没有帮助。

标签: elasticsearch logging filter filebeat


【解决方案1】:

我希望我能理解你的问题,但在这种情况下,我会走上 grok 路线。

如果你知道你的状态字段总是这样,那为什么不做这样的模式:

match => { 
  "message" => "<prepending patterns> status: %{NUMBER:httpresponsecode} <patterns that follow>" 
}

这将创建一个名为httpresponsecode 的字段,其中填充了字符串"status: " 后面的数字

但是,基于ECS-Formats,我宁愿将该字段称为其他名称,例如
http.response.status(.keyword)

对于您指定的日志行,有效的 grok 模式可能如下所示:

%{TIMESTAMP_ISO8601:timestamp} %{NONNEGINT:message.number} %{WORD:loglevel} %{DATA:application} \[-\] %{IP:source.ip} "(?:%{WORD:verb} %{NOTSPACE:http.request.path}(?: HTTP/%{NUMBER:http.version})?|%{DATA:rawrequest})" status: %{NONNEGINT:http.response.status} len: %{NUMBER:http.response.length} time: %{NUMBER:http.response.time}

logstash repository 中找到用于 logstash 的 Grok 模式 使用 Grok-Debugger included in Kibana 查看您的模式将如何匹配。

相应地重命名字段。

【讨论】:

  • 嗨,这对于解决方案来说没问题,但你能帮我为这些行创建这个:2018-11-22 03:49:12.508 116770 INFO nova.osapi_compute.wsgi.server [-] 10.118.220.228 "OPTIONS / HTTP/1.0" status: 200 len: 505 time: 0.0005932 我只是对状态感兴趣,但我必须为他们提供这种模式。
  • 如果你使用kibana,应该包含一个grok-debugger,否则你可以试试this one。找到 grok 模式here 我已经更新了答案,但是,您应该真正考虑自己编写 grok 过滤器。对于数据摄取和准备,这是您的第一站。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-27
  • 2023-03-10
相关资源
最近更新 更多