【发布时间】:2017-05-18 21:00:53
【问题描述】:
我在 docker 容器中运行本地服务器,该容器设置为使用 fluentd 作为日志驱动程序。 我有 docker compose 文件,它在自己的容器中运行 fluentd、nginx、elasticsearch 和 kibana。 所以 fluentd 从我的服务器获取日志,将其传递给 elasticsearch 并显示在 Kibana 上。
我的问题是,如何在 fluentd 中解析我的日志(如果在 fluentd 中不可能,则使用 Elasticsearch 或 kibana)来制作新标签,这样我就可以对它们进行排序并更轻松地导航。
这是 Kibana 中显示的当前日志。现在我希望这个日志字符串被“分解”成新的标签。在这种情况下:
2017/01/04 13:26:56.574909 UTC (Example deployment.web) [INFO] [GET] /api/device/ 200 10.562379ms
到
date: 2017/01/04
time: 13:26:56.574909 UTC
message: (Example deployment.web)
logType: [INFO]
other: [GET] /api/device/ 200 10.562379ms
我的 docker-compose.yml
version: "2"
services:
fluentd:
image: fluent/fluentd:latest
ports:
- "24224:24224"
volumes:
- ./fluentd/etc:/fluentd/etc
command: /fluentd/etc/start.sh
networks:
- lognet
elasticsearch:
image: elasticsearch
ports:
- "9200:9200"
- "9300:9300"
volumes:
- /usr/share/elasticsearch/data:/usr/share/elasticsearch/data
networks:
- lognet
kibana:
image: kibana
restart: always
ports:
- "5601:5601"
environment:
- ELASTICSEARCH_URL=http://localhost:9200
networks:
- lognet
nginx:
image: nginx
ports:
- "8084:80"
logging:
driver: fluentd
networks:
- lognet
networks:
lognet:
driver: bridge
我的fluent.conf文件,不包括解析,只是简单的转发
<source>
type forward
</source>
<match *.*>
type elasticsearch
host elasticsearch
logstash_format true
flush_interval 10s
</match>
我尝试使用正则表达式,这里我尝试解析 logType
<source>
@type forward
</source>
<match *.*>
type stdout
</match>
<filter docker.**>
@type parser
format /(?<logType>\[([^\)]+)\])/
key_name log
reserve_data false
</filter>
我尝试了其他配置,但都无法解析我的日志。
【问题讨论】:
标签: logging elasticsearch docker kibana fluentd