diff --git a/.env.example b/.env.example index 6f90eaf..fdfc352 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,13 @@ -COMPOSE_PROFILES=grafana,promtail +COMPOSE_PROFILES=grafana GRAFANA_VERSION=9.1.7 -LOKI_STACK_VERSION=2.6.0 \ No newline at end of file +GRAFANA_HOST=grafana.docker.localhost + +LOKI_STACK_VERSION=2.6.0 +LOKI_HOST=loki.docker.localhost +LOKI_PROMTAIL_HOST=promtail.docker.localhost + +PROMETHEUS_VERSION=v2.43.0 +PROMETHEUS_NODE_EXPORTER_VERSION=v1.5.0 +PROMETHEUS_HOST=prometheus.docker.localhost +PROMETHEUS_RETENTION_TIME=10d diff --git a/.gitignore b/.gitignore index 0d12e13..24d7237 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.idea/ +/.vscode/ /.env -/docker-compose.override.yml \ No newline at end of file +/docker-compose.override.yml diff --git a/docker-compose.yml b/docker-compose.yml index 8a8bc8d..b15f5c4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,9 +4,9 @@ version: "3.9" services: grafana: image: grafana/grafana:${GRAFANA_VERSION:-latest} - labels: + labels: - "traefik.enable=true" - - "traefik.http.routers.grafana.rule=Host(`grafana.docker.localhost`)" + - "traefik.http.routers.grafana.rule=Host(`${GRAFANA_HOST}`)" - "traefik.http.services.grafana.loadbalancer.server.port=3000" expose: - 3000 @@ -17,10 +17,10 @@ services: - grafana loki: - image: grafana/loki:${LOKI_STACK_VERSION:-2.6.0} - labels: + image: grafana/loki:${LOKI_STACK_VERSION} + labels: - "traefik.enable=true" - - "traefik.http.routers.loki.rule=Host(`loki.docker.localhost`)" + - "traefik.http.routers.loki.rule=Host(`${LOKI_HOST}`)" - "traefik.http.services.loki.loadbalancer.server.port=3100" expose: - 3100 @@ -29,12 +29,12 @@ services: command: --config.file=/loki/config/config.yml profiles: - grafana - + promtail: - image: grafana/promtail:${LOKI_STACK_VERSION:-2.6.0} + image: grafana/promtail:${LOKI_STACK_VERSION} labels: - "traefik.enable=true" - - "traefik.http.routers.grafana.rule=Host(`promtail.docker.localhost`)" + - "traefik.http.routers.grafana.rule=Host(`${LOKI_PROMTAIL_HOST}`)" - "traefik.http.services.grafana.loadbalancer.server.port=9080" expose: - 9080 @@ -46,5 +46,43 @@ services: profiles: - promtail + prometheus: + image: prom/prometheus:${PROMETHEUS_VERSION} + labels: + - "traefik.enable=true" + - "traefik.http.routers.prometheus.rule=Host(`${PROMETHEUS_HOST}`)" + - "traefik.http.services.prometheus.loadbalancer.server.port=9090" + command: + - '--config.file=/etc/prometheus/prometheus.yml' + - '--storage.tsdb.path=/prometheus' + - '--storage.tsdb.retention.time=${PROMETHEUS_RETENTION_TIME:-10d}' + - '--web.console.libraries=/usr/share/prometheus/console_libraries' + - '--web.console.templates=/usr/share/prometheus/consoles' + expose: + - 9090 + volumes: + - ./prometheus/:/etc/prometheus/ + - prometheus-data:/prometheus + profiles: + - prometheus + + node-exporter: + image: prom/node-exporter:${PROMETHEUS_NODE_EXPORTER_VERSION} + restart: on-failure + volumes: + - /proc:/host/proc:ro + - /sys:/host/sys:ro + - /:/rootfs:ro + command: + - '--path.procfs=/host/proc' + - '--path.sysfs=/host/sys' + - --collector.filesystem.ignored-mount-points + - "^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)" + expose: + - 9100 + profiles: + - prometheus + volumes: grafana-storage: + prometheus-data: diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml new file mode 100644 index 0000000..04c0730 --- /dev/null +++ b/prometheus/prometheus.yml @@ -0,0 +1,19 @@ +--- +global: + scrape_interval: 15s + evaluation_interval: 15s + external_labels: + monitor: 'dev-prometheus' + +scrape_config_files: + - /etc/prometheus/scrapes/*.yml + +scrape_configs: + - job_name: 'prometheus' + scrape_interval: 15s + static_configs: + - targets: ['localhost:9090'] + - job_name: 'node-exporter' + scrape_interval: 15s + static_configs: + - targets: ['node-exporter:9100'] diff --git a/prometheus/scrapes/.gitignore b/prometheus/scrapes/.gitignore new file mode 100644 index 0000000..a68d087 --- /dev/null +++ b/prometheus/scrapes/.gitignore @@ -0,0 +1,2 @@ +/* +!/.gitignore