services:
    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.enable-lifecycle
        container_name: prometheus
        image: prom/prometheus:latest
        labels:
            traefik.docker.network: traefik
            traefik.enable: true
            traefik.http.routers.prometheus.entrypoints: websecure
            traefik.http.routers.prometheus.rule: Host(`prometheus.alexlebens.net`)
            traefik.http.routers.prometheus.service: prometheus
            traefik.http.routers.prometheus.middlewares: authentik@file
            traefik.http.services.prometheus.loadbalancer.server.port: 9090
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
        privileged: true
        restart: always
        user: root
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - prometheus_config:/etc/prometheus
            - prometheus_data:/prometheus
            - alertmanager:/alertmanager

    alertmanager:
        command:
            - --config.file=/alertmanager/alertmanager.yml
        container_name: prometheus_alertmanager
        depends_on:
            - prometheus
        image: prom/alertmanager:latest
        labels:
            traefik.docker.network: traefik
            traefik.enable: true
            traefik.http.routers.alertmanager.entrypoints: websecure
            traefik.http.routers.alertmanager.rule: Host(`alertmanager.alexlebens.net`)
            traefik.http.routers.alertmanager.service: alertmanager
            traefik.http.routers.alertmanager.middlewares: authentik@file
            traefik.http.services.alertmanager.loadbalancer.server.port: 9093
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
        privileged: true
        restart: always
        user: root
        volumes:
            - alertmanager:/alertmanager

    node_exporter:
        container_name: prometheus_node_exporter
        image: prom/node-exporter:latest
        depends_on:
            - alertmanager
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
        privileged: true
        restart: always
        volumes:
            - /host:/host
            - /var/lib/docker/volumes/partition:/partition

    snmp_exporter:
        command:
            - --config.file=/etc/snmp_exporter/snmp.yml
        container_name: prometheus_snmp_exporter
        depends_on:
            - node_exporter
        dns:
            - 192.168.1.15
        image: prom/snmp-exporter:latest
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
        restart: unless-stopped
        volumes:
            - snmp_exporter:/etc/snmp_exporter

    cadvisor:
        container_name: prometheus_cadvisor
        image: gcr.io/cadvisor/cadvisor:v0.46.0
        depends_on:
            - snmp_exporter
        labels:
            traefik.docker.network: traefik
            traefik.enable: true
            traefik.http.routers.cadvisor.entrypoints: websecure
            traefik.http.routers.cadvisor.rule: Host(`cadvisor.alexlebens.net`)
            traefik.http.routers.cadvisor.service: cadvisor
            traefik.http.routers.cadvisor.middlewares: authentik@file
            traefik.http.services.cadvisor.loadbalancer.server.port: 8080
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
        privileged: true
        restart: always
        volumes:
            - /cgroup:/cgroup:ro
            - /dev/disk/:/dev/disk:ro
            - /:/rootfs:ro
            - /sys:/sys:ro
            - /var/lib/docker/:/var/lib/docker:ro
            - /var/run:/var/run:ro

    unpoller:
        container_name: prometheus_unpoller
        depends_on:
            - cadvisor
        env_file:
            - .env
        image: golift/unifi-poller:latest
        logging:
            driver: json-file
            options:
                max-size: 50m
                max-file: "3"
        networks:
            traefik: null
        restart: always

networks:
    traefik:
        name: traefik
        external: true

volumes:
    prometheus_config:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/prometheus_config

    prometheus_data:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/prometheus

    alertmanager:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/prometheus_alertmanager

    snmp_exporter:
        driver: local
        driver_opts:
            type: none
            o: bind
            device: /var/lib/docker/volumes/partition/prometheus_snmp_exporter
