Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Update test stack
Browse files Browse the repository at this point in the history
  • Loading branch information
socheatsok78 committed Jun 22, 2024
1 parent 2cd8aa8 commit 5c96924
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 330 deletions.
7 changes: 1 addition & 6 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
docker-stack-name = test_prometheus
docker-stack-name = echo

it:
@echo "make [deploy|remove|clean|reset] docker-stack-name=$(docker-stack-name)"

networks:
@docker network create --scope=swarm --driver=overlay --attachable dockerswarm_ingress > /dev/null 2>&1 || true
@docker network create --scope=swarm --driver=overlay --attachable dockerswarm_metrics > /dev/null 2>&1 || true
@docker network create --scope=swarm --driver=overlay --attachable prometheus_exporters > /dev/null 2>&1 || true

deploy: networks
docker stack deploy -c docker-stack.yml $(docker-stack-name)

Expand Down
14 changes: 14 additions & 0 deletions test/configs/echo-scrape-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://json.schemastore.org/prometheus.json
#
# Scrape config for Docker Swarm Nodes
#
# The Docker Engine metrics are required to be configured in the daemon.json file for Prometheus to scrape them.
# This configuration also includes a job to scrape the Node Exporter metrics that run on each node.
scrape_configs:
- job_name: 'echo-scrape-config'

static_configs:
- targets:
- 'localhost:80'
labels:
app: 'echo'
302 changes: 15 additions & 287 deletions test/docker-stack.yml
Original file line number Diff line number Diff line change
@@ -1,294 +1,22 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/swarmlibs/dockerstack-schema/main/schema/dockerstack-spec.json

x-default-logging: &x-default-logging
options:
max-size: "12m"
max-file: "5"
driver: json-file

x-exporter-resources-constraints: &x-exporter-resources-constraints
limits:
memory: 128M
reservations:
memory: 64M

volumes:
alertmanager-data:
alertmanager-configs:

prometheus-data:
prometheus-configs:

networks:
dockerswarm_ingress:
name: dockerswarm_ingress
external: true
dockerswarm_metrics:
name: dockerswarm_metrics
external: true
prometheus_exporters:
name: prometheus_exporters
external: true

services:

# ====================================================
# Prometheus
# https://github.com/prometheus/prometheus
# ====================================================

prometheus:
image: swarmlibs/prometheus:local
deploy:
mode: global
placement:
max_replicas_per_node: 1
constraints:
- node.role == manager
labels:
io.prometheus.role: "prometheus"
io.prometheus.dockerswarm-tasks.should_be_scraped: "false"
io.prometheus.dockerswarm-services.should_be_probed: "false"
logging: *x-default-logging
environment:
- DOCKERSWARM_SERVICE_ID={{.Service.ID}}
- DOCKERSWARM_SERVICE_NAME={{.Service.Name}}
- DOCKERSWARM_NODE_ID={{.Node.ID}}
- DOCKERSWARM_NODE_HOSTNAME={{.Node.Hostname}}
- DOCKERSWARM_TASK_ID={{.Task.ID}}
- DOCKERSWARM_TASK_NAME={{.Task.Name}}
- DOCKERSWARM_TASK_SLOT={{.Task.Slot}}
- DOCKERSWARM_STACK_NAMESPACE={{ index .Service.Labels "com.docker.stack.namespace"}}

# Cluster Alertmanager address
- PROMETHEUS_ALERTMANAGER_ADDR=tasks.alertmanager
ports:
- published: 9090
target: 9090
mode: host
hostname: prometheus.svc.cluster.local
networks:
dockerswarm_ingress:
dockerswarm_metrics:
prometheus_exporters:
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
read_only: true
- type: volume
source: prometheus-data
target: /prometheus/data
- type: volume
source: prometheus-configs
target: /prometheus-configs.d

prometheus-config-reloader:
image: quay.io/prometheus-operator/prometheus-config-reloader:v0.74.0
command:
- --listen-address=:8080
- --watched-dir=/prometheus-configs.d
- --reload-url=http://host.docker.internal:9090/-/reload
- --runtimeinfo-url=http://host.docker.internal:9090/api/v1/status/runtimeinfo
- --watch-interval=15s
- --reload-timeout=10s
deploy:
mode: global
resources: *x-exporter-resources-constraints
placement:
max_replicas_per_node: 1
constraints:
- node.role == manager
labels:
io.prometheus.role: "prometheus-config-reloader"
io.prometheus.enabled: "true"
io.prometheus.job_name: "prometheus-config-reloader"
io.prometheus.scrape_port: "8080"
io.prometheus.dockerswarm-services.should_be_probed: "false"
logging: *x-default-logging
networks:
dockerswarm_metrics:
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- type: volume
source: prometheus-configs
target: /prometheus-configs.d

# ====================================================
# Alertmanager
# https://github.com/prometheus/alertmanager
# ====================================================

alertmanager:
image: swarmlibs/alertmanager:main
deploy:
mode: global
placement:
max_replicas_per_node: 1
constraints:
- node.role == manager
labels:
io.prometheus.role: "alertmanager"
io.prometheus.dockerswarm-tasks.should_be_scraped: "false"
io.prometheus.dockerswarm-services.should_be_probed: "false"
logging: *x-default-logging
environment:
- DOCKERSWARM_SERVICE_ID={{.Service.ID}}
- DOCKERSWARM_SERVICE_NAME={{.Service.Name}}
- DOCKERSWARM_NODE_ID={{.Node.ID}}
- DOCKERSWARM_NODE_HOSTNAME={{.Node.Hostname}}
- DOCKERSWARM_TASK_ID={{.Task.ID}}
- DOCKERSWARM_TASK_NAME={{.Task.Name}}
- DOCKERSWARM_TASK_SLOT={{.Task.Slot}}
- DOCKERSWARM_STACK_NAMESPACE={{ index .Service.Labels "com.docker.stack.namespace"}}
echo-server:
image: ealen/echo-server:latest
ports:
- published: 9093
target: 9093
- published: 18080
target: 80
mode: host
hostname: alertmanager.{{.Node.ID}}.cluster.local
networks:
dockerswarm_metrics:
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- type: volume
source: alertmanager-data
target: /alertmanager
network_01:
network_02:

alertmanager-config-reloader:
image: quay.io/prometheus-operator/prometheus-config-reloader:v0.74.0
command:
- --listen-address=:8080
- --watched-dir=/alertmanager-configs.d
- --reload-url=http://host.docker.internal:9093/-/reload
deploy:
mode: global
resources: *x-exporter-resources-constraints
placement:
max_replicas_per_node: 1
constraints:
- node.role == manager
labels:
io.prometheus.role: "alertmanager-config-reloader"
io.prometheus.enabled: "true"
io.prometheus.job_name: "alertmanager-config-reloader"
io.prometheus.scrape_port: "8080"
io.prometheus.dockerswarm-services.should_be_probed: "false"
logging: *x-default-logging
networks:
dockerswarm_metrics:
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- type: volume
source: alertmanager-configs
target: /alertmanager-configs.d

# ====================================================
# Blackbox prober exporter
# https://github.com/prometheus/blackbox_exporter
# ====================================================

blackbox-exporter:
image: prom/blackbox-exporter:latest
deploy:
replicas: 1
resources: *x-exporter-resources-constraints
labels:
io.prometheus.role: "blackbox-exporter"
io.prometheus.enabled: "true"
io.prometheus.job_name: "blackbox-exporter"
io.prometheus.scrape_port: "9115"
io.prometheus.dockerswarm-services.should_be_probed: "false"
logging: *x-default-logging
hostname: blackbox-exporter.svc.cluster.local
networks:
dockerswarm_ingress:
dockerswarm_metrics:
prometheus_exporters:

# ====================================================
# Node exporter
# https://github.com/prometheus/node_exporter
# ====================================================

node-exporter:
image: swarmlibs/node-exporter:main
deploy:
mode: global
resources: *x-exporter-resources-constraints
labels:
io.prometheus.role: "node-exporter"
io.prometheus.dockerswarm-tasks.should_be_scraped: "false"
io.prometheus.dockerswarm-services.should_be_probed: "false"
logging: *x-default-logging
ports:
- published: 9100
target: 9100
mode: host
networks:
prometheus_exporters:
hostname: node-exporter.{{.Node.ID}}.cluster.local
volumes:
- type: bind
source: /
target: /rootfs
read_only: true

# ====================================================
# cAdvisor
# https://github.com/google/cadvisor
# ====================================================

cadvisor:
image: gcr.io/cadvisor/cadvisor:v0.47.0
command: -logtostderr -docker_only
deploy:
mode: global
resources: *x-exporter-resources-constraints
labels:
io.prometheus.role: "cadvisor"
io.prometheus.dockerswarm-tasks.should_be_scraped: "false"
io.prometheus.dockerswarm-services.should_be_probed: "false"
logging: *x-default-logging
ports:
- published: 8080
target: 8080
mode: host
networks:
prometheus_exporters:
hostname: cadvisor.{{.Node.ID}}.cluster.local
volumes:
- type: bind
source: /
target: /rootfs
read_only: true
- type: bind
source: /var/run
target: /var/run
read_only: true
- type: bind
source: /sys
target: /sys
read_only: true
- type: bind
source: /var/lib/docker
target: /var/lib/docker
read_only: true
- type: bind
source: /var/run/docker.sock
target: /var/run/docker.sock
read_only: true
# If you are running Docker Desktop on macOS,
# You'll need to comment out the following bind mounts
# - type: bind
# source: /dev/disk
# target: /dev/disk
# read_only: true
# - type: bind
# source: /dev/kmsg
# target: /dev/kmsg
# read_only: true
networks:
network_01:
network_02:

configs:
echo-scrape-config.yml:
file: test/configs/echo-scrape-config.yml
labels:
- "io.prometheus.scrape_config=true"
21 changes: 0 additions & 21 deletions test/echo-scrape-config.yml

This file was deleted.

16 changes: 0 additions & 16 deletions test/echo-stack.yml

This file was deleted.

0 comments on commit 5c96924

Please sign in to comment.