Skip to content

Commit

Permalink
replace (brittle) promtail-based Docker logging with new loki-docker-…
Browse files Browse the repository at this point in the history
…driver
  • Loading branch information
Mike Holloway committed Jun 28, 2019
1 parent 0cde768 commit d8aea29
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 85 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@ Docker compose file for Grafana Loki, like Prometheus but for logs. Requires Doc

## INSTALLATION

On every one of your Docker nodes, create a directory and cron job that will populate container names:
On every Docker swarm node, first install Loki's Docker log driver plugin (it's important to install the plugin before modifying /etc/docker/daemon.json)

```
mkdir -p /etc/promtail/targets
crontab -e
docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
```

and add the following line to your root cron (or cron of a user that can execute /bin/docker):
Next, add the following (at least the log-driver and log-opts below) to the file /etc/docker/daemon.json on each Docker swarm node:

```
* * * * * docker ps --no-trunc --format '- targets: ["{{.ID}}"]\n labels:\n container_name: "{{.Names}}"' > /etc/promtail/targets/promtail-targets.yaml
{
"debug" : false,
"log-driver": "loki",
"log-opts": {
"loki-url": "http://SWARM-FQDN-OR-IP:3100/api/prom/push",
"loki-batch-size": "400"
}
}
```

Non-[swarmstack](https://github.com/swarmstack/swarmstack) users will need to edit promtail-docker-config.yaml and change the clients url from http://loki:3100/.. to the IP or DNS of one of your Docker nodes.
Finally, restart the Docker daemon on each swarm node (draining nodes first if necessary) to pick up the logging change:

```
docker node update --availbility drain node1.fqdn
systemctl restart docker
docker node update --availbility active node1.fqdn
```

## USAGE

Expand Down
20 changes: 2 additions & 18 deletions docker-compose-swarmstack.yaml → docker-compose-swarmstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ volumes:
configs:
loki_config:
file: ./loki-local-config.yaml
promtail_config:
file: ./promtail-docker-config.yaml

services:
loki:
Expand All @@ -35,21 +33,7 @@ services:
constraints:
- node.Labels.storagegroup==RED
replicas: 1
ports:
- "3100:3100"
volumes:
- loki-data:/data/loki

promtail:
image: grafana/promtail:v0.1.0
command: -config.file=/etc/promtail/promtail-docker-config.yaml
configs:
- source: promtail_config
target: /etc/promtail/promtail-docker-config.yaml
deploy:
labels:
prometheus.enable: "true"
prometheus.port: "9080"
prometheus.path: "/metrics"
mode: global
volumes:
- /var/lib/docker/containers:/var/lib/docker/containers:ro
- /etc/promtail/targets:/etc/promtail/targets:ro
37 changes: 0 additions & 37 deletions docker-compose.yaml

This file was deleted.

20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: "3.4"

configs:
loki_config:
file: ./loki-local-config.yaml

services:
loki:
image: grafana/loki:v0.1.0
command: -config.file=/etc/loki/loki-local-config.yaml
configs:
- source: loki_config
target: /etc/loki/loki-local-config.yaml
deploy:
mode: replicated
replicas: 1
ports:
- "3100:3100"
volumes:
- ./local_bind_volume_dir:/data/loki
22 changes: 0 additions & 22 deletions promtail-docker-config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion up
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

docker stack deploy -c docker-compose.yaml loki
docker stack deploy -c docker-compose.yml loki
2 changes: 1 addition & 1 deletion up-swarmstack
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

docker stack deploy -c docker-compose-swarmstack.yaml loki
docker stack deploy -c docker-compose-swarmstack.yml loki

0 comments on commit d8aea29

Please sign in to comment.