Skip to content

Commit

Permalink
swarm example with promethues
Browse files Browse the repository at this point in the history
  • Loading branch information
rjchicago committed Feb 7, 2022
1 parent 3b3ec30 commit 89e645c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
27 changes: 26 additions & 1 deletion docker-stack.yml → examples/swarm/docker-stack.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
version: "3.8"

networks:
docker-event-metrics-net:

services:
swarm:
image: rjchicago/docker-event-metrics:${VERSION:-latest}
networks:
- docker-event-metrics-net
environment:
ENV: "${ENV:-local}"
OPTIONS: '{"filter": {"scope": "swarm"}}'
Expand All @@ -15,6 +20,8 @@ services:

local:
image: rjchicago/docker-event-metrics:${VERSION:-latest}
networks:
- docker-event-metrics-net
environment:
ENV: "${ENV:-local}"
INSTANCE: "{{.Node.Hostname}}"
Expand All @@ -25,4 +32,22 @@ services:
- "8077:3000"
deploy:
mode: global


prometheus:
image: prom/prometheus
networks:
- docker-event-metrics-net
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
deploy:
replicas: 1

test:
image: alpine
command: tail -f /dev/null
networks:
- docker-event-metrics-net
deploy:
replicas: 1
9 changes: 9 additions & 0 deletions examples/swarm/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: 'docker-events'
static_configs:
- targets: [swarm:3000,local:3000]

44 changes: 44 additions & 0 deletions examples/swarm/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Docker Swarm

## deploy

``` sh
docker stack deploy -c docker-stack.yml docker-event-metrics --prune
```

## test

Create some events...

``` sh
docker network create test
docker network rm test
docker run -it --rm alpine echo "hello"
docker service update --replicas 3 docker-event-metrics_test
docker service rm docker-event-metrics_test
```

Open ./metrics endpoints:

> <http://localhost:8076/metrics>
> <http://localhost:8077/metrics>
## prometheus

Open in Prometheus...

> <http://localhost:9090>
Example graph

> <http://localhost:9090/graph?g0.expr=rate(docker_events%5B2m%5D)%20%3E%200&g0.tab=0&g0.stacked=0&g0.show_exemplars=0&g0.range_input=30m>
``` sql
rate(docker_events[2m]) > 0
```

## cleanup

``` sh
docker stack rm docker-event-metrics
```

0 comments on commit 89e645c

Please sign in to comment.