【发布时间】:2020-10-07 06:51:20
【问题描述】:
我正在尝试在 docker 中运行 Fluent-bit 并使用 Loki 在 Grafana 中查看日志,但我在 Grafana 中看不到任何标签。 Loki 数据源报告它可以工作并找到标签。
我需要弄清楚如何从 fluent-bit -> loki -> grafana 获取 docker 日志。任何日志。
这是我的docker-compose.yaml
version: "3.3"
networks:
loki:
external: true
services:
fluent-bit:
image: grafana/fluent-bit-plugin-loki:latest
container_name: fluent-bit
environment:
LOKI_URL: http://loki:3100/loki/api/v1/push
networks:
- loki
volumes:
- ./fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
logging:
options:
tag: infra.monitoring
这是我的配置文件。
[INPUT]
Name forward
Listen 0.0.0.0
Port 24224
[Output]
Name loki
Match *
Url ${LOKI_URL}
RemoveKeys source
Labels {job="fluent-bit"}
LabelKeys container_name
BatchWait 1
BatchSize 1001024
LineFormat json
LogLevel info
这是我的 Grafana 和 Loki 设置
grafana:
image: grafana/grafana
depends_on:
- prometheus
container_name: grafana
volumes:
- grafana_data:/var/lib/grafana:rw
- ./grafana/provisioning:/etc/grafana/provisioning
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_USERS_ALLOW_SIGN_UP=false
- GF_INSTALL_PLUGINS=grafana-piechart-panel
- GF_RENDERING_SERVER_URL=http://renderer:8081/render
- GF_RENDERING_CALLBACK_URL=http://grafana:3000/
- GF_LOG_FILTERS=rendering:debug
restart: unless-stopped
networks:
- traefik
- loki
labels:
- "traefik.enable=true"
- "traefik.http.routers.grafana.rule=Host(`grafana-int.mydomain.com`)"
- "traefik.http.services.grafana.loadbalancer.server.port=3000"
- "traefik.docker.network=traefik"
loki:
image: grafana/loki:latest
container_name: loki
expose:
- "3100"
networks:
- loki
renderer:
image: grafana/grafana-image-renderer:2.0.0
container_name: grafana-image-renderer
expose:
- "8081"
environment:
ENABLE_METRICS: "true"
networks:
- loki
我已尝试使用下面评论中链接的文档中描述的以下配置,但仍然没有标签。
[SERVICE]
Flush 1
Log_Level info
Parsers_File parsers.conf
[INPUT]
Name syslog
Path /tmp/in_syslog
Buffer_Chunk_Size 32000
Buffer_Max_Size 64000
[OUTPUT]
Name loki
Match *
Url ${LOKI_URL}
RemoveKeys source
Labels {job="fluent-bit"}
LabelKeys container_name
BatchWait 1
BatchSize 1001024
LineFormat json
LogLevel info
我尝试了这个配置,但仍然没有标签。
[INPUT]
@type tail
format json
read_from_head true
path /var/log/syslog
pos_file /tmp/container-logs.pos
[OUTPUT]
Name loki
Match *
Url ${LOKI_URL}
RemoveKeys source
LabelKeys container_name
BatchWait 1
BatchSize 1001024
LineFormat json
LogLevel info
【问题讨论】:
-
你在使用
fluent-bit和fluentd的配置文件吗?请看fluent-bit配置:docs.fluentbit.io/manual/v/1.2/configuration/file -
fluent-bit 配置架构:docs.fluentbit.io/manual/v/1.2/configuration/schema
-
该示例适用于 fluentd。您是否尝试按原样将其用于 fluent-bit?
-
我不确定。我相信,根据您之前的评论,您希望将 syslog 日志发送到 grafana。从 syslog 输入插件文档中,它看起来像是传入 syslog 条目的侦听器/接收器。因此,如果用于发送默认系统日志条目的用例,那么您需要使用先前的配置和
tail到系统日志路径,例如/var/log/syslog。我想这更有意义。如果是 syslog 输入插件,则没有从 syslog 到 fluent-bit 的 syslog 输入插件的默认路由。因此,不会有任何活动日志。