From 40e1a80f9fe2da664918c9697a607658042df711 Mon Sep 17 00:00:00 2001 From: asepharyana Date: Thu, 23 Jul 2026 07:45:59 +0700 Subject: [PATCH] feat(infra): auto-discovery Prometheus + Traefik metrics - Prometheus: add docker_sd_configs for auto-discovery via labels - Prometheus: mount Docker socket for Docker SD - Traefik: enable --metrics.prometheus with entrypoint/service labels - Traefik: add prometheus.io/scrape=true label - Observability: mount Docker socket for Prometheus container - Bump hub submodule (Traefik metrics queries + sparkline charts) Co-Authored-By: Claude Opus 4.8 (1M context) --- apps/hub | 2 +- infra/compose/observability.yml | 1 + infra/compose/traefik.yml | 5 +++++ infra/otel/prometheus.yml | 27 +++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/hub b/apps/hub index 72f4759..d14ed70 160000 --- a/apps/hub +++ b/apps/hub @@ -1 +1 @@ -Subproject commit 72f4759f8bc11d6bc6fffac63ea9b56074f2fc2d +Subproject commit d14ed702404f846031040feefdb0a5d9474ebfda diff --git a/infra/compose/observability.yml b/infra/compose/observability.yml index d619cf6..12e342c 100644 --- a/infra/compose/observability.yml +++ b/infra/compose/observability.yml @@ -55,6 +55,7 @@ services: volumes: - ../../infra/otel/prometheus.yml:/etc/prometheus/prometheus.yml:ro - /prometheus + - /var/run/docker.sock:/var/run/docker.sock:ro # ── Node Exporter (Host Metrics: CPU, RAM, Disk) ── node-exporter: diff --git a/infra/compose/traefik.yml b/infra/compose/traefik.yml index 0e42bf8..3e72fd6 100644 --- a/infra/compose/traefik.yml +++ b/infra/compose/traefik.yml @@ -50,6 +50,9 @@ services: - '--experimental.plugins.blockpath.moduleName=github.com/traefik/plugin-blockpath' - '--experimental.plugins.blockpath.version=v0.2.1' - '--ping=true' + - '--metrics.prometheus=true' + - '--metrics.prometheus.addEntryPointsLabels=true' + - '--metrics.prometheus.addServicesLabels=true' - '--tracing.otlp=true' - '--tracing.otlp.http=true' - '--tracing.otlp.http.endpoint=http://otel-collector:4318' @@ -77,6 +80,8 @@ services: - 'traefik.http.routers.traefik.entrypoints=websecure' - 'traefik.http.routers.traefik.tls=true' - 'traefik.http.routers.traefik.middlewares=admin-chain@file' + - 'prometheus.io/scrape=true' + - 'prometheus.io/port=8080' networks: app-shared-net: diff --git a/infra/otel/prometheus.yml b/infra/otel/prometheus.yml index 4a95860..52ad7c2 100644 --- a/infra/otel/prometheus.yml +++ b/infra/otel/prometheus.yml @@ -3,6 +3,32 @@ global: evaluation_interval: 15s scrape_configs: + # ── Docker SD: containers with prometheus.io/scrape=true are auto-discovered ── + - job_name: 'docker' + docker_sd_configs: + - host: unix:///var/run/docker.sock + refresh_interval: 15s + filters: + - name: label + values: + - prometheus.io/scrape=true + relabel_configs: + - source_labels: [__meta_docker_container_name] + target_label: container + regex: '/(.*)' + replacement: '${1}' + - source_labels: [__meta_docker_container_label_prometheus_io_port] + regex: '(.+)' + target_label: __metrics_path__ + replacement: '/metrics' + - source_labels: [__meta_docker_container_label_prometheus_io_path] + regex: '(.+)' + target_label: __metrics_path__ + replacement: '${1}' + - source_labels: [__address__] + target_label: instance + + # ── OTel Collector ── - job_name: 'otel-collector' scrape_interval: 10s metrics_path: /metrics @@ -11,6 +37,7 @@ scrape_configs: labels: service: otel-collector + # ── Node Exporter ── - job_name: 'node' scrape_interval: 15s static_configs: