- 環境搭建
1.es安裝
選用版本6.6.2
2.kibana安裝
選用版本6.6.2
3.fluentd安裝
選用版本td-agent3.7.1
td-agent.conf中配置說明
fluentd官網
https://docs.fluentd.org/parser/multiline
####
## Output descriptions:
##
# Treasure Data (http://www.treasure-data.com/) provides cloud based data
# analytics platform, which easily stores and processes data from td-agent.
# FREE plan is also provided.
# @see http://docs.fluentd.org/articles/http-to-td
#
# This section matches events whose tag is td.DATABASE.TABLE
## match tag=debug.** and dump to console
#tag類型匹配 這裏表示匹配test
<match test.**>
#表示寫入es
@type elasticsearch
#是否開啓logstash日誌格式化
logstash_format true
#flush時間間隔
flush_interval 10s
#es連接ip
host localhost
#es連接端口號
port 9200
#在es創建得index名稱 這裏使用tag-時間
index_name ${tag}-%Y.%m.%d
#在es創建得type 這裏使用tag-時間
type_name ${tag}-%Y.%m.%d
logstash_prefix ${tag}
include_tag_key true
tag_key @log_name
<buffer tag, time>
timekey 1h
</buffer>
</match>
####
## Source descriptions:
##
## built-in TCP input
## @see http://docs.fluentd.org/articles/in_forward
#監聽tcp 默認ip localhost port 24224 可通過tcp得方式發送日誌到fluentd
<source>
@type forward
@id input_forward
</source>
## built-in UNIX socket input
#<source>
# type unix
#</source>
# HTTP input
# POST http://localhost:8888/<tag>?json=<json>
# POST http://localhost:8888/td.myapp.login?json={"user"%3A"me"}
# @see http://docs.fluentd.org/articles/in_http
#可接受http類型得日誌發送請求 默認ip localhost
<source>
@type http
@id input_http
#端口8888
port 8888
#限制大小32m
body_size_limit 32m
#限制超時時間10s
keepalive_timeout 10s
</source>
## live debugging agent
<source>
@type debug_agent
@id input_debug_agent
bind 127.0.0.1
port 24230
</source>
#tail類型讀取日誌文件
<source>
@type tail
#文件路徑(自定義)
path /suns/log/td-agent/*.test.log
#記錄讀取位置得文件(自定義)
pos_file /suns/log/td-agent/test.log.pos
#沒有讀取記錄時是否從頭開始讀
read_from_head true
#多行匹配篩選日誌(這裏爲自定義日誌)
<parse>
@type multiline
format_firstline /^Begin:/ #這裏時指以Begin:這一行爲開始
format1 /^Url:(?<Url>.*)/ #這裏是匹配Url忽略:
format2 /^RequestParams:(?<RequestParams>.*)/ #這裏匹配RequestParams忽略:
format3 /^ResponseResults:(?<ResponseResults>.*)/ #這裏匹配ResponseResults忽略:
format4 /^Cost:(?<Cost>.*)/ #這裏匹配Cost忽略:
format5 /^End/
</parse>
tag test
</source>
kibana操作
1.查看索引
2.創建索引模式
3.Discover查看日誌監控
4.可創建可視化(可選)
5.創建儀表盤(可選)
- es head安裝
參考https://blog.csdn.net/weixin_33092023/article/details/80765775 - 從springboot項目直接發送日誌到fluentd
1.引入依賴
<dependency>
<groupId>org.fluentd</groupId>
<artifactId>fluent-logger</artifactId>
<version>0.3.3</version>
</dependency>
- 本地調用遠程fluent服務
//service-a.ServiceController tag前綴
private static FluentLogger log = FluentLogger.getLogger(“service-a.ServiceController”,“192.168.181.99”,24224);
然後調用log.log方法指定tag,日誌級別和日誌內容。
也可在日誌得xml文件中指定apperder來發送(具體可查看官網)