---

service_port_grafana: 3000
service_port_prometheus: 9090
service_port_alertmanager: 9093

prometheus_id: "{{ inventory_hostname }}-prometheus"
alertmanager_id: "{{ inventory_hostname }}-alertmanager"
grafana_id: "{{ inventory_hostname }}-grafana"
prom2teams_id: "{{ inventory_hostname }}-prom2teams"

prometheus_docker: {
  networks: [
    {
      name: back-tier,
      external: true,
    },
    {
      name: front-tier,
      external: true,
    },
  ],
  volumes: [
    {
      name: "{{ prometheus_id }}-data"
    },
    {
      name: "{{ alertmanager_id }}-data"
    },
    {
      name: "{{ grafana_id }}-data"
    },
  ],
  services: [
    {
      name: "{{ prometheus_id }}",
      image_name: "{{ prometheus_image_name }}",
      image_version: "{{ prometheus_image_version }}",
      labels: [
        '"traefik.enable=true"',
        '"traefik.http.routers.{{ prometheus_id }}.service={{ prometheus_id }}"',
        '"traefik.http.routers.{{ prometheus_id }}.rule=Host(`{{ inventory_hostname }}-prometheus.{{ domain }}`)"',
        '"traefik.http.routers.{{ prometheus_id }}.entrypoints=websecure"',
        '"traefik.http.routers.{{ prometheus_id }}.tls=true"',
        '"traefik.http.routers.{{ prometheus_id }}.tls.certresolver=letsencrypt"',
        '"traefik.http.services.{{ prometheus_id }}.loadbalancer.server.port={{ service_port_prometheus }}"',
      ],
      command: [
        '"--config.file=/etc/prometheus/prometheus.yml"',
        '"--storage.tsdb.path=/prometheus"',
        '"--web.console.libraries=/usr/share/prometheus/console_libraries"',
        '"--web.console.templates=/usr/share/prometheus/consoles"',
        '"--web.external-url={{ http_s}}://{{ inventory_hostname }}-prometheus.{{ domain }}"',
        '"--web.enable-lifecycle"',
        '"--storage.tsdb.retention.time={{ prometheus_tsdb_rentention_time | default("4w")}}"',
      ],
      volumes: [
        '"./config/prometheus/:/etc/prometheus/:ro"',
        '"{{ prometheus_id }}-data:/prometheus"',
      ],
      networks: [
        '"back-tier"',
        '"front-tier"',
      ],
      extra_hosts: "{{ prometheus_extra_hosts | default([]) }}",
    },
    {
      name: "{{ alertmanager_id }}",
      image_name: "{{ alertmanager_image_name }}",
      image_version: "{{ alertmanager_image_version }}",
      labels: [
        '"traefik.enable=true"',
        '"traefik.http.routers.{{ alertmanager_id }}.service={{ alertmanager_id }}"',
        '"traefik.http.routers.{{ alertmanager_id }}.rule=Host(`{{ inventory_hostname }}-alertmanager.{{ domain }}`)"',
        '"traefik.http.routers.{{ alertmanager_id }}.entrypoints=websecure"',
        '"traefik.http.routers.{{ alertmanager_id }}.tls=true"',
        '"traefik.http.routers.{{ alertmanager_id }}.tls.certresolver=letsencrypt"',
        '"traefik.http.services.{{ alertmanager_id }}.loadbalancer.server.port={{ service_port_alertmanager }}"',
      ],
      command: [
        '"--config.file=/etc/alertmanager/config.yml"',
        '"--storage.path=/alertmanager"',
        '"--web.external-url={{ http_s}}://{{ inventory_hostname }}-alertmanager.{{ domain }}"',
      ],
      environment: [
        'LS_JAVA_OPTS: "-Xmx1G -Xms1G"',
      ],
      volumes: [
        '"./config/alertmanager/:/etc/alertmanager/:ro"',
        '"{{ alertmanager_id }}-data:/alertmanager"',
      ],
      networks: [
        '"back-tier"',
        '"front-tier"',
      ],
    },
    {
      name: "{{ grafana_id }}",
      image_name: "{{ grafana_image_name }}",
      image_version: "{{ grafana_image_version }}",
      user: '"472"',
      labels: [
        '"traefik.enable=true"',
        '"traefik.http.routers.{{ grafana_id }}.service={{ grafana_id }}"',
        '"traefik.http.routers.{{ grafana_id }}.rule=Host(`{{ inventory_hostname }}-grafana.{{ domain }}`)"',
        '"traefik.http.routers.{{ grafana_id }}.entrypoints=websecure"',
        '"traefik.http.routers.{{ grafana_id }}.tls=true"',
        '"traefik.http.routers.{{ grafana_id }}.tls.certresolver=letsencrypt"',
        '"traefik.http.services.{{ grafana_id }}.loadbalancer.server.port={{ service_port_grafana }}"',
      ],
      volumes: [
        '"./config/grafana/provisioning/:/etc/grafana/provisioning/"',
        '"./config/grafana/conf/defaults.ini:/usr/share/grafana/conf/defaults.ini"',
        '"{{ grafana_id }}-data:/var/lib/grafana"',
      ],
      networks: [
        '"back-tier"',
        '"front-tier"',
      ],
      env_file: [
        '"./config/grafana/config.monitoring"',
      ],
    },
    {
      name: "{{ prom2teams_id }}",
      image_name: "{{ prom2teams_image_name }}",
      image_version: "{{ prom2teams_image_version }}",
      volumes: [
        '"./config/prom2teams/config.ini:/opt/prom2teams/config.ini"',
      ],
      networks: [
        '"back-tier"',
      ],
    },
  ],
}
