docker-compose.yml

  1. cat > docker-compose.yml << EOF
  2. version: "3.7"
  3. services:
  4. promtail:
  5. image: grafana/promtail
  6. container_name: promtail
  7. restart: always
  8. volumes:
  9. # 要收集三方日志,需要映射路径
  10. # - ./config.yml:/etc/promtail/config.yml
  11. # 日志路径
  12. - /var/lib/docker/containers:/var/log
  13. command: -config.file=/etc/promtail/config.yml # 默认配置
  14. networks:
  15. default:
  16. external:
  17. name: jcbnet
  18. EOF

配置

  1. docker-compose up -d
  2. docker cp promtail:/etc/promtail/config.yml ./
  3. sed -i "s/# -/-/g" docker-compose.yml
  4. docker-compose up -d

config.yaml

说明:

默认配置内容如下:

  1. server:
  2. http_listen_port: 9080
  3. grpc_listen_port: 0
  4. positions:
  5. filename: /var/log/positions.yaml # This location needs to be writeable by Promtail.
  6. client:
  7. url: http://ip_or_hostname_where_Loki_run:3100/loki/api/v1/push
  8. scrape_configs:
  9. - job_name: system
  10. pipeline_stages:
  11. static_configs:
  12. - labels:
  13. job: varlogs # A `job` label is fairly standard in prometheus and useful for linking metrics and logs.
  14. host: ${yourhost} # A `host` label will help identify logs from this machine vs others
  15. __path__: /var/log/**/*-json.log # The path matching uses a third party library: https://github.com/bmatcuk/doublestar