docker-compose.yml
cat > docker-compose.yml << EOF
version: "3.7"
services:
promtail:
image: grafana/promtail
container_name: promtail
restart: always
volumes:
# 要收集三方日志,需要映射路径
# - ./config.yml:/etc/promtail/config.yml
# 日志路径
- /var/lib/docker/containers:/var/log
command: -config.file=/etc/promtail/config.yml # 默认配置
networks:
default:
external:
name: jcbnet
EOF
配置
docker-compose up -d
docker cp promtail:/etc/promtail/config.yml ./
sed -i "s/# -/-/g" docker-compose.yml
docker-compose up -d
config.yaml
说明:
默认配置内容如下:
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /var/log/positions.yaml # This location needs to be writeable by Promtail.
client:
url: http://ip_or_hostname_where_Loki_run:3100/loki/api/v1/push
scrape_configs:
- job_name: system
pipeline_stages:
static_configs:
- labels:
job: varlogs # A `job` label is fairly standard in prometheus and useful for linking metrics and logs.
host: ${yourhost} # A `host` label will help identify logs from this machine vs others
__path__: /var/log/**/*-json.log # The path matching uses a third party library: https://github.com/bmatcuk/doublestar