自己在测试环境中尝试编写一些简单的日志规则,于是拿mongodb的日志进行测试,整体的ELK环境这里不再讲了,主要从客户端的filebeat开始
我们去mongodb服务器上安装filebeat
01.wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.4.0-x86_64.rpm02.yum localinstall filebeat-7.4.0-x86_64.rpm
然后我们去配置filebeat
01.#cat /etc/filebeat/filebeat.yml02. 03.filebeat.inputs:04.- type: log05. enabled: true06. paths:07. - /usr/local/mongodb/logs/mongodb.log08. tags: ["mongo-logs"]09. 10.filebeat.config.modules:11. path: ${path.config}/modules.d/*.yml12. reload.enabled: false13.setup.template.settings:14. index.number_of_shards: 115.setup.kibana:16.#output.elasticsearch:17.# hosts: ["localhost:9200"]18.output.logstash:19. hosts: ["122.51.230.106:5044"]20.processors:21. - add_host_metadata: ~22. - add_cloud_metadata: ~
接着我们需要去logstash里面去配置过略规则
01.input {02. beats {03. port => 504404. codec => plain {05. charset => "UTF-8"06. }07. }08.}09.filter {10. if "mongo-logs" in [tags] {11. grok {12. match => ["message", '%{TIMESTAMP_ISO8601:timestamp} %{NOTSPACE:i} %{NOTSPACE:opeariton} (?<info>(.)*)']13. }14. mutate {15. remove_field => ["message"]16. remove_field => ["i"]17. }18. }19. 20. if "beats_input_codec_plain_applied" in [tags] {21. mutate {22. remove_tag => ["beats_input_codec_plain_applied"]23. }24. }25.}26. 27.output {28. if "mongo-logs" in [tags] {29. elasticsearch {30. hosts => "122.51.230.106:9200"31. manage_template => false32. index => "mongo-%{+YYYY.MM.dd}"33. #document_type => "%{[@metadata][type]}"34. }35. }36. 37.}
grok的规则我们可以在kibana上可以边测试边写,在开发工具Grok Debugger内
添加索引这里也不在赘述了,最后我们在kibana上查看下收集的的mongodb的日志
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://sulao.cn/post/750
评论列表