Skip to content

Instantly share code, notes, and snippets.

@linxlunx
Created December 15, 2022 08:38
Show Gist options
  • Save linxlunx/27c633e40a64e4c10e307e668fd41130 to your computer and use it in GitHub Desktop.
Save linxlunx/27c633e40a64e4c10e307e668fd41130 to your computer and use it in GitHub Desktop.
Promtail config and docker run
docker run -it --rm --name containerName -p 80:80 --log-driver json-file --log-opt tag="{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}" imageName:imageTag
server:
http_listen_address: 0.0.0.0
http_listen_port: 9080
positions:
filename: /tmp/positions.yaml
clients:
- url: http://user:pwd@loki-host:loki-port/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log
- job_name: containers
static_configs:
- targets:
- localhost
labels:
job: containerlogs
__path__: /var/lib/docker/containers/*/*log
pipeline_stages:
- json:
expressions:
output: log
stream: stream
attrs:
- json:
expressions:
tag:
source: attrs
- regex:
expression: (?P<image_name>(?:[^|]*[^|])).(?P<container_name>(?:[^|]*[^|])).(?P<image_id>(?:[^|]*[^|])).(?P<container_id>(?:[^|]*[^|]))
source: "tag"
- timestamp:
format: RFC3339Nano
source: time
- labels:
tag:
stream:
image_name:
container_name:
image_id:
container_id:
- output:
source: output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment