version: '3.9'
services:
  prometheus:
    image: prom/prometheus:v2.47.0
    command:
    - --config.file=/etc/prometheus/prometheus.yml
    - --storage.tsdb.path=/prometheus
    - --web.console.libraries=/etc/prometheus/console_libraries
    - --web.console.templates=/etc/prometheus/consoles
    - --storage.tsdb.retention.time=30d
    - --web.enable-lifecycle
    - --web.enable-admin-api
    volumes:
    - prometheus_data:/prometheus
    - /opt/configs/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
    networks:
    - monitoring-network
    - caddy-public
    ports:
    - 9090:9090
    healthcheck:
      test:
      - CMD
      - wget
      - --no-verbose
      - --tries=1
      - --spider
      - http://localhost:9090/-/healthy
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
    deploy:
      resources:
        limits:
          memory: 1G
          cpus: '0.5'
        reservations:
          memory: 512M
          cpus: '0.25'
      labels:
      - traefik.enable=true
      - traefik.http.routers.prometheus.rule=Host(`prometheus.pressmess.duckdns.org`)
      - traefik.http.routers.prometheus.entrypoints=websecure
      - traefik.http.routers.prometheus.tls=true
      - traefik.http.services.prometheus.loadbalancer.server.port=9090

  grafana:
    image: grafana/grafana:10.1.2
    environment:
      GF_PROVISIONING_PATH: /etc/grafana/provisioning
      GF_INSTALL_PLUGINS: grafana-clock-panel,grafana-simple-json-datasource,grafana-piechart-panel
      GF_FEATURE_TOGGLES_ENABLE: publicDashboards
      GF_SECURITY_ADMIN_PASSWORD: admin123
    volumes:
    - grafana_data:/var/lib/grafana
    networks:
    - monitoring-network
    - caddy-public
    healthcheck:
      test:
      - CMD-SHELL
      - curl -f http://localhost:3000/api/health || exit 1
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    deploy:
      resources:
        limits:
          memory: 1G
          cpus: '0.5'
        reservations:
          memory: 512M
          cpus: '0.25'
      labels:
      - traefik.enable=true
      - traefik.http.routers.grafana.rule=Host(`grafana.pressmess.duckdns.org`)
      - traefik.http.routers.grafana.entrypoints=websecure
      - traefik.http.routers.grafana.tls=true
      - traefik.http.services.grafana.loadbalancer.server.port=3000

  alertmanager:
    image: prom/alertmanager:v0.26.0
    command:
    - --config.file=/etc/alertmanager/alertmanager.yml
    - --storage.path=/alertmanager
    - --web.external-url=http://localhost:9093
    volumes:
    - alertmanager_data:/alertmanager
    - /opt/configs/monitoring/alertmanager.yml:/etc/alertmanager/alertmanager.yml:ro
    networks:
    - monitoring-network
    - caddy-public
    ports:
    - 9093:9093
    healthcheck:
      test:
      - CMD
      - wget
      - --no-verbose
      - --tries=1
      - --spider
      - http://localhost:9093/-/healthy
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: '0.25'
        reservations:
          memory: 256M
          cpus: '0.1'
      labels:
      - traefik.enable=true
      - traefik.http.routers.alertmanager.rule=Host(`alertmanager.pressmess.duckdns.org`)
      - traefik.http.routers.alertmanager.entrypoints=websecure
      - traefik.http.routers.alertmanager.tls=true
      - traefik.http.services.alertmanager.loadbalancer.server.port=9093

volumes:
  prometheus_data:
    driver: local
  grafana_data:
    driver: local
  alertmanager_data:
    driver: local

networks:
  monitoring-network:
    external: true
  caddy-public:
    external: true
