运行logstash
# logstash
version: '3'
services:logstash:image: docker.elastic.co/logstash/logstash:8.12.0container_name: logstash_serverrestart: alwaysports:- 8065:8065environment:- LS_JAVA_OPTS=-Xmx1024m -Xms1024mvolumes:- ./config/logstash.conf:/etc/logstash/conf.d/logstash.conf # 读取宿主机配置entrypoint:- logstash- -f- /etc/logstash/conf.d/logstash.conflogging:driver: "json-file"options:max-size: "200m"max-file: "3"
logstash
运行后进入容器
# 安装logstash-output-loki插件
logstash-plugin install logstash-output-loki
修改logstash
配置
// logstash.conf
input {tcp {port=> 8065codec => "json"}
}output {loki{url => "http://loki:3100/loki/api/v1/push"}
}
重启logstash
运行loki
# loki
version: '3'
services:loki:image: grafana/lokicontainer_name: lokirestart: alwaysports:- "3100:3100"command: -config.file=/etc/loki/local-config.yaml
运行grafana
version: '3'
services:grafana:image: grafana/grafanacontainer_name: grafanahostname: grafanarestart: alwaysports:- "3000:3000"
进入grafana
,打开左侧菜单,点击Administration
点击Plugin
,搜索loki
进入选项后点击Add new data source
输入loki
地址,http://localhost:3100
配置成功
查询日志
左侧菜单,explore
,选择过滤条件后,Run query
进行查询
https://github.com/grafana/loki/issues/9755
https://grafana.com/docs/loki/latest/send-data/logstash/
https://github.com/grafana/loki/issues/2886