Filebeat官方文档地址

https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-installation.html

下载和安装

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.3.1-linux-x86_64.tar.gz
tar xzvf filebeat-7.3.1-linux-x86_64.tar.gz

编写filebeat.yml

启动

chmod go-w /home/lintong/software/apache/filebeat-7.3.1-linux-x86_64/filebeat.yml
./filebeat -e -c filebeat.yml

codec.format

codec.format:
string: '%{[@timestamp]} %{[message]}'

输出

2019-09-13T17:06:51.797Z 123123123123

codec.json

codec.json:
pretty: true
escape_html: false

输出

{
"@timestamp": "2019-09-13T09:08:49.590Z",
"@metadata": {
"beat": "filebeat",
"type": "_doc",
"version": "7.3.1",
"topic": "thrift_json_source"
},
"host": {
"name": "lintong-B250M-DS3H"
},
"agent": {
"version": "7.3.1",
"type": "filebeat",
"ephemeral_id": "60b93a10-dcce-499b-ae81-0755bfc8bf5c",
"hostname": "lintong-B250M-DS3H",
"id": "6ebb0912-ffce-4ddd-9cc8-7bf624e62c78"
},
"ecs": {
"version": "1.0.1"
},
"message": "123123123123",
"log": {
"file": {
"path": "/home/lintong/下载/test.log"
},
"offset": 0
},
"input": {
"type": "log"
}
}

如果pretty是false将输出

{"@timestamp":"2019-09-13T09:10:50.164Z","@metadata":{"beat":"filebeat","type":"_doc","version":"7.3.1","topic":"thrift_json_source"},"log":{"file":{"path":"/home/lintong/下载/test.log"},"offset":0},"message":"123123123123","input":{"type":"log"},"ecs":{"version":"1.0.1"},"host":{"name":"lintong-B250M-DS3H"},"agent":{"type":"filebeat","ephemeral_id":"b26075f9-37f8-4d95-9341-fccc4504c1b5","hostname":"lintong-B250M-DS3H","id":"6ebb0912-ffce-4ddd-9cc8-7bf624e62c78","version":"7.3.1"}}

如果需要添加字段

  paths:
- /home/lintong/下载/test.log
fields:
add_field: lintong

输出

{
"@timestamp": "2019-09-16T08:16:06.169Z",
"@metadata": {
"beat": "filebeat",
"type": "_doc",
"version": "7.3.1",
"topic": "thrift_json_source"
},
"host": {
"name": "lintong-B250M-DS3H"
},
"log": {
"offset": 31,
"file": {
"path": "/home/lintong/下载/test.log"
}
},
"message": "33333333",
"input": {
"type": "log"
},
"fields": {
"add_field": "lintong"
},
"agent": {
"type": "filebeat",
"ephemeral_id": "c16102da-421d-4ff3-90ad-1737451a909d",
"hostname": "lintong-B250M-DS3H",
"id": "6ebb0912-ffce-4ddd-9cc8-7bf624e62c78",
"version": "7.3.1"
},
"ecs": {
"version": "1.0.1"
}
}

在codec.format中添加字段

  codec.format:
string: '%{[@timestamp]} %{[fields.add_field]} %{[message]}'

输出

2019-09-16T16:18:34.048Z lintong 55555555

如果想添加的字段在json的顶层,就是不在fields字段下层

  paths:
- /home/lintong/下载/test.log
fields:
add_field: lintong
fields_under_root: true

输出

{
"@timestamp": "2019-09-16T08:22:43.997Z",
"@metadata": {
"beat": "filebeat",
"type": "_doc",
"version": "7.3.1",
"topic": "thrift_json_source"
},
"agent": {
"ephemeral_id": "d8e45d90-6434-4e0d-a6fc-74611b87cbd4",
"hostname": "lintong-B250M-DS3H",
"id": "6ebb0912-ffce-4ddd-9cc8-7bf624e62c78",
"version": "7.3.1",
"type": "filebeat"
},
"log": {
"offset": 58,
"file": {
"path": "/home/lintong/下载/test.log"
}
},
"message": "66666666",
"add_field": "lintong",
"input": {
"type": "log"
},
"ecs": {
"version": "1.0.1"
},
"host": {
"name": "lintong-B250M-DS3H"
}
}

如果要去掉不要的字段

参考:

https://studygolang.com/articles/10935

https://www.elastic.co/guide/en/beats/filebeat/current/drop-fields.html

比如

processors:
- drop_fields:
fields: ["host", "log", "input","ecs","agent"]

输出

{
"@timestamp": "2019-09-16T08:55:55.934Z",
"@metadata": {
"beat": "filebeat",
"type": "_doc",
"version": "7.3.1",
"topic": "thrift_json_source"
},
"message": "33333333",
"add_field": "lintong"
}

其中@metadata和@timestamp不能在filebeat中去掉

最新文章

  1. ubuntu终端窗口最大化(不是全屏)
  2. eclipse发布web项目到生产环境的方式汇总(tomcat)
  3. iOS 短信分享 邮件分享
  4. UVA 540 stl
  5. ARM1138@库函数速查
  6. CSS 背景图片的定位和缩放
  7. shell中$0,$?,$!
  8. JS的事件动态绑定机制
  9. SQL Server 2005入门到精通(案例详解)
  10. Xamarin Forms 进度条控件
  11. Jfinal拦截器源码解读
  12. C++第四课:类的使用(二)[个人见解]
  13. mui弹出菜单
  14. 上传jar包到maven中央仓库过程中遇到的一些问题总结!
  15. CCF CSP 201809-1 卖菜
  16. kafka---->kafka connect的使用(一)
  17. .net core部署到Ubuntu
  18. vue-cli 选项无法选问题
  19. keydown,keypress,keyup三者之间的区别
  20. php,perl计算crc

热门文章

  1. 汉字转拼音,TinyPinyin、Pinyin4j与JPinyin哪个库更快
  2. 常见的Redis面试"刁难"问题,值得一读
  3. 二、hexo+github搭建个人博客的简单使用
  4. R数据挖掘 第三篇:聚类的评估(簇数确定和轮廓系数)和可视化
  5. 脱离 WebView 的通信 JavaScriptCore
  6. 【01】Jenkins:安装配置
  7. C语言语法教程-结构体
  8. 单词大学CET六四级英语
  9. .net core+topshelf+quartz创建windows定时任务服务
  10. Golang 模块(Module)官方手册