---
# docker-compose file for prometheus metrics server

# docker login dkregistry.xai-corp.net:5000
# docker-compose build && docker push dkregistry.xai-corp.net:5000/xaicorp/prometheus:latest

# DOCKER_HOST=dkmanager:2376 docker stack deploy --prune --with-registry-auth -c docker-compose-prod.yml metrics
# DOCKER_HOST=dkmanager:2376 docker stack ps metrics

version: '3.4'
volumes:
  prometheus-storage:
  grafana-storage:

services:

  prometheus:
    image: "dkregistry.xai-corp.net:5000/xaicorp/prometheus:latest"
    ports:
      - 9090:9090
    volumes:
      - prometheus-storage:/prometheus
    healthcheck:
      test: ["CMD", "wget", "--spider", "http://localhost:9090/metrics"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 3m
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: any
        delay: "1s"
        max_attempts: 5
      update_config:
        parallelism: 1
        delay: 2s
        order: start-first
      resources:
        limits:
#          cpus: '1'
          memory: 512M

  graphana:
    image: grafana/grafana
    ports:
      - 3001:3000
    volumes:
      - grafana-storage:/var/lib/grafana
    environment:
      GF_SECURITY_ADMIN_PASSWORD: sakas
      GF_INSTALL_PLUGINS: 'grafana-clock-panel,grafana-simple-json-datasource,raintank-worldping-app'
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: any
        delay: "1m"
        max_attempts: 1
      update_config:
        parallelism: 1
        delay: 2s
        order: start-first
      resources:
        limits:
          memory: 512M
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/metrics"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 3m

  postgres_exporter:
    image: wrouesnel/postgres_exporter
    ports:
      - 9187:9187
    environment:
      DATA_SOURCE_NAME: "postgresql://xaicorp_admin:snqioxni1sw@tasks.postgres:5432/?sslmode=disable"
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: any
        delay: "1s"
        max_attempts: 5
      update_config:
        parallelism: 1
        delay: 2s
        order: start-first
      resources:
        limits:
#          cpus: '1'
          memory: 512M


  fluentd_exporter:
    image: vect0r/fluentd_exporter
    ports:
      - 9309:9309
    command:
      - go-wrapper
      - run
      - -scrape_uri
      - http://tasks.fluentd:24220/api/plugins.json
    deploy:
      mode: replicated
      replicas: 1
      restart_policy:
        condition: any
        delay: "1s"
        max_attempts: 5
      update_config:
        parallelism: 1
        delay: 2s
        order: start-first
      resources:
        limits:
#          cpus: '1'
          memory: 512M


  node_exporter:
    image: quay.io/prometheus/node-exporter
    ports:
      - 9100:9100
    command:
      - --collector.tcpstat

  statsd_exporter:
    image: prom/statsd-exporter
    ports:
      - 9102:9102
      - 9125:9125
      - 9125:9125/udp

networks:
  prod:
    external:
      name: prod
