From 89e645cfcdc14322e910a25ca8ee8d8a9a5e6c92 Mon Sep 17 00:00:00 2001 From: Ryan Jones Date: Sun, 6 Feb 2022 22:25:53 -0600 Subject: [PATCH] swarm example with promethues --- .../swarm/docker-stack.yml | 27 +++++++++++- examples/swarm/prometheus.yml | 9 ++++ examples/swarm/readme.md | 44 +++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) rename docker-stack.yml => examples/swarm/docker-stack.yml (56%) create mode 100644 examples/swarm/prometheus.yml create mode 100644 examples/swarm/readme.md diff --git a/docker-stack.yml b/examples/swarm/docker-stack.yml similarity index 56% rename from docker-stack.yml rename to examples/swarm/docker-stack.yml index fd3de28..36a5898 100644 --- a/docker-stack.yml +++ b/examples/swarm/docker-stack.yml @@ -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"}}' @@ -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}}" @@ -25,4 +32,22 @@ services: - "8077:3000" deploy: mode: global - \ No newline at end of file + + 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 diff --git a/examples/swarm/prometheus.yml b/examples/swarm/prometheus.yml new file mode 100644 index 0000000..2939d16 --- /dev/null +++ b/examples/swarm/prometheus.yml @@ -0,0 +1,9 @@ +global: + scrape_interval: 15s + evaluation_interval: 15s + +scrape_configs: + - job_name: 'docker-events' + static_configs: + - targets: [swarm:3000,local:3000] + \ No newline at end of file diff --git a/examples/swarm/readme.md b/examples/swarm/readme.md new file mode 100644 index 0000000..f9faabb --- /dev/null +++ b/examples/swarm/readme.md @@ -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: + +> +> + +## prometheus + +Open in Prometheus... + +> + +Example graph + +> + +``` sql +rate(docker_events[2m]) > 0 +``` + +## cleanup + +``` sh +docker stack rm docker-event-metrics +``` \ No newline at end of file