-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display docker logs with human/logical name #333
Comments
@leominov yeah that's fine for removing a bit of noise but I mean the ability to select a log for one container by its name. The attached image might help: |
My current solution (not in production yet) for docker is to use a cron job that runs docker ps --format '- targets: ["{{.ID}}"]\n labels:\n container_name: "{{.Names}}"' > /etc/promtail/promtail-targets.yaml Then in the promtail config use relabeling to get the log files: server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
client:
url: http://loki:3100/api/prom/push
scrape_configs:
- job_name: containers
entry_parser: docker
file_sd_configs:
- files:
- /etc/promtail/promtail-targets.yaml
relabel_configs:
- source_labels: [__address__]
target_label: container_id
- source_labels: [container_id]
target_label: __path__
replacement: /var/lib/docker/containers/$1*/*.log A Docker logging driver ala #195 or logspout ala #82 would be better of course, but in the meantime this seems to work, mostly: I've been having problems removing containers while promtail is running, since it's holding open the log file. |
Thanks for that @retzkek , that's good enough for me right now. For whatever reason something wasn't seeing the change but I happened to update to the latest Grafana beta (3) along with the latest promtail and loki and it's showing as expected. Cheers, |
@tomwilkie do you think it need to support in the future? |
@retzkek is there a way to do this with pipeline stages as well? thanks! |
@ratio91 I haven't had a chance to do any more with loki, sorry. Since the docker container logs are just json by default it should be straightforward to do. https://github.com/grafana/loki/blob/master/docs/logentry/processing-log-lines.md |
You can use the docker driver now and will automatically named correctly container/stack/service. see https://github.com/grafana/loki/blob/master/cmd/docker-driver/README.md |
FYI: Scraping the docker container logs only works as long as they are stored in json format. Recently, the |
You can use this config (json-driver supports this, i don't know about the other drivers). docker run --log-opt tag="{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}" ... server:
http_listen_address: 0.0.0.0
http_listen_port: 9080
positions:
filename: /tmp/positions.yaml
clients:
- url: http://loki:3100/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
__path__: /var/log/*log
- job_name: containers
entry_parser: raw
static_configs:
- targets:
- localhost
labels:
job: containerlogs
__path__: /var/lib/docker/containers/*/*log
# --log-opt tag="{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}"
pipeline_stages:
- json:
expressions:
stream: stream
attrs: attrs
tag: attrs.tag
- regex:
expression: (?P<image_name>(?:[^|]*[^|])).(?P<container_name>(?:[^|]*[^|])).(?P<image_id>(?:[^|]*[^|])).(?P<container_id>(?:[^|]*[^|]))
source: "tag"
- labels:
tag:
stream:
image_name:
container_name:
image_id:
container_id:
|
Hi , how do you scrape docker logs , is it required to use sudo somehow to fetch the logs? |
Depends on your system, although you don't need to care about any files if you use the docker driver. https://github.com/grafana/loki/tree/master/cmd/docker-driver |
Did you find a wat not to lock the logs files ? Something like Read Only mode ? |
…on-5.9 [release-5.9] operator: Remove duplicate conditions from status
I have promtail set up to scrape Docker container logs and can view them in loki/grafana.
I'm wondering if there's a solution to displaying them with meaningful names, like the names giving to the container? My promtail config looks like:
So currently if I go to Explore in Grafana and select Loki, I can choose the entire dockerlogs job or individual files - the JSON logs are obviously their file name which doesn't mean much to people without host access or looking through each.
I'm not using Kubernetes. Do I need to create some kind of custom label which will survive a container being redeployed?
If this is a stupid question I'm happy to be pointed to some code or doc that will help me.
Really liking this already though.
The text was updated successfully, but these errors were encountered: