# NetPulse stack: InfluxDB + Grafana + the speedtest runner. # # Copy .env.example to .env and fill in the required values first; compose # stops with a message naming any required value that is missing. # Published ports bind to ${NETPULSE_BIND_ADDR:-127.0.0.1}; see .env.example. services: influxdb: # influxdb:2.7.12 - Dependabot moves the tag and the digest together. image: influxdb:2.9.1@sha256:e4572d094ac3272f06528ea904ce6b4cb3bb19be2db3b3b1acbd27ba5c3a73e2 container_name: netpulse-influxdb restart: unless-stopped security_opt: - no-new-privileges:true mem_limit: 2g pids_limit: 512 ports: - "${NETPULSE_BIND_ADDR:-127.0.0.1}:8086:8086" volumes: - influxdb-data:/var/lib/influxdb2 - influxdb-config:/etc/influxdb2 environment: - DOCKER_INFLUXDB_INIT_MODE=setup - DOCKER_INFLUXDB_INIT_USERNAME=${INFLUXDB_USERNAME:-admin} - DOCKER_INFLUXDB_INIT_PASSWORD=${INFLUXDB_PASSWORD:?set INFLUXDB_PASSWORD in .env} - DOCKER_INFLUXDB_INIT_ORG=${INFLUXDB_ORG:-netpulse} - DOCKER_INFLUXDB_INIT_BUCKET=${INFLUXDB_BUCKET:-netpulse} - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${INFLUXDB_TOKEN:?set INFLUXDB_TOKEN in .env} networks: - netpulse-network grafana: # grafana/grafana:12.4.14 - Dependabot moves the tag and the digest together. image: grafana/grafana:13.3.1@sha256:0615ec4fbd4072004b7d86b46ded63013a74b7d6eb1119273dd89e8fa25c13cf container_name: netpulse-grafana restart: unless-stopped security_opt: - no-new-privileges:true mem_limit: 512m pids_limit: 256 ports: - "${NETPULSE_BIND_ADDR:-127.0.0.1}:3000:3000" volumes: - grafana-data:/var/lib/grafana - ./grafana/provisioning:/etc/grafana/provisioning:ro - ./grafana/dashboards:/var/lib/grafana/dashboards:ro environment: - GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-admin} - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:?set GRAFANA_PASSWORD in .env} # Read by grafana/provisioning/datasources/influxdb.yml (environment expansion) - INFLUXDB_TOKEN=${INFLUXDB_TOKEN:?set INFLUXDB_TOKEN in .env} - INFLUXDB_ORG=${INFLUXDB_ORG:-netpulse} - INFLUXDB_BUCKET=${INFLUXDB_BUCKET:-netpulse} depends_on: - influxdb networks: - netpulse-network # ─── Simplified runner: Ookla-based speed test (always runs) ────────────── speedtest-runner: build: context: ./speedtest-runner dockerfile: Dockerfile container_name: netpulse-runner restart: unless-stopped # The runner needs no privileges: it makes outbound requests and writes # its state file to the volume below. cap_drop: - ALL security_opt: - no-new-privileges:true read_only: true tmpfs: # Scratch space; HOME points here because the Ookla CLI writes its # license acceptance under HOME and the root filesystem is read-only. - /tmp mem_limit: 256m cpus: 1.0 pids_limit: 128 healthcheck: # Dependency-free liveness check: the runner is PID 1 of the container. test: ["CMD", "python", "-c", "import sys; sys.exit(0 if b'speedtest_runner' in open('/proc/1/cmdline', 'rb').read() else 1)"] interval: 60s timeout: 5s retries: 3 start_period: 15s environment: # InfluxDB version: "1" or "2" (default: 2) - INFLUXDB_VERSION=${INFLUXDB_VERSION:-2} - INFLUXDB_URL=http://influxdb:8086 # InfluxDB 2.x settings (token-based) - INFLUXDB_TOKEN=${INFLUXDB_TOKEN:?set INFLUXDB_TOKEN in .env} - INFLUXDB_ORG=${INFLUXDB_ORG:-netpulse} - INFLUXDB_BUCKET=${INFLUXDB_BUCKET:-netpulse} # General settings - SPEEDTEST_INTERVAL=${SPEEDTEST_INTERVAL:-1800} - SPEEDTEST_CRON=${SPEEDTEST_CRON:-} - HIDE_EXTERNAL_IP=${HIDE_EXTERNAL_IP:-false} - TZ=${TZ:-America/New_York} - NETPULSE_STATE_FILE=/data/state.json - HOME=/tmp volumes: - netpulse-state:/data depends_on: - influxdb networks: - netpulse-network # Continuous loss/latency/jitter probe. Opt-in: start it with # docker compose --profile probe up -d # Same image and the same lockdown as the runner. ICMP uses an unprivileged # datagram socket, so it needs no added capability; if the kernel does not # allow it, ICMP targets fall back to TCP port 443. probe: profiles: - probe build: context: ./speedtest-runner dockerfile: Dockerfile command: ["python", "-u", "probe.py"] container_name: netpulse-probe restart: unless-stopped cap_drop: - ALL security_opt: - no-new-privileges:true read_only: true tmpfs: - /tmp mem_limit: 128m cpus: 0.5 pids_limit: 64 healthcheck: test: ["CMD", "python", "-c", "import sys; sys.exit(0 if b'probe.py' in open('/proc/1/cmdline', 'rb').read() else 1)"] interval: 60s timeout: 5s retries: 3 start_period: 15s environment: - INFLUXDB_VERSION=${INFLUXDB_VERSION:-2} - INFLUXDB_URL=http://influxdb:8086 - INFLUXDB_TOKEN=${INFLUXDB_TOKEN:?set INFLUXDB_TOKEN in .env} - INFLUXDB_ORG=${INFLUXDB_ORG:-netpulse} - INFLUXDB_BUCKET=${INFLUXDB_BUCKET:-netpulse} - PROBE_TARGETS=${PROBE_TARGETS:-icmp:1.1.1.1,tcp:1.1.1.1:443,https:https://www.cloudflare.com/} - PROBE_INTERVAL=${PROBE_INTERVAL:-60} - PROBE_COUNT=${PROBE_COUNT:-5} - PROBE_TIMEOUT=${PROBE_TIMEOUT:-2} - PROBE_TIMING=${PROBE_TIMING:-1} - TZ=${TZ:-America/New_York} depends_on: - influxdb networks: - netpulse-network # ─── Enhanced runner: Cloudflare-based speed test (opt-in via profile) ───── # Same secret rule as the other services (required token, no default) and the # same lockdown as the runner. Start it with: docker compose --profile enhanced up -d cloudflare-runner: profiles: - enhanced build: context: ./cloudflare-speedtest-runner dockerfile: Dockerfile container_name: netpulse-cloudflare-runner restart: unless-stopped cap_drop: - ALL security_opt: - no-new-privileges:true read_only: true tmpfs: - /tmp mem_limit: 256m cpus: 1.0 pids_limit: 128 healthcheck: test: ["CMD", "python", "-c", "import sys; sys.exit(0 if b'cloudflare_speedtest_runner' in open('/proc/1/cmdline', 'rb').read() else 1)"] interval: 60s timeout: 5s retries: 3 start_period: 15s environment: # InfluxDB version: "1" or "2" (default: 2) - INFLUXDB_VERSION=${INFLUXDB_VERSION:-2} - INFLUXDB_URL=http://influxdb:8086 # InfluxDB 2.x settings (token-based) - INFLUXDB_TOKEN=${INFLUXDB_TOKEN:?set INFLUXDB_TOKEN in .env} - INFLUXDB_ORG=${INFLUXDB_ORG:-netpulse} - INFLUXDB_BUCKET=${INFLUXDB_BUCKET:-netpulse} # Scheduling: interval (seconds) or cron expression # Default: every 6 hours. Clock-based example: "0 3,9,15,21 * * *" - SPEEDTEST_INTERVAL=${CF_SPEEDTEST_INTERVAL:-21600} - SPEEDTEST_CRON=${CF_SPEEDTEST_CRON:-} # Privacy: set to "true" to mask the external IP in InfluxDB/Grafana - HIDE_EXTERNAL_IP=${HIDE_EXTERNAL_IP:-false} - TZ=${TZ:-America/New_York} - NETPULSE_STATE_FILE=/data/cf_state.json # Cloudflare test tuning - CF_LATENCY_SAMPLES=${CF_LATENCY_SAMPLES:-20} volumes: - netpulse-state:/data depends_on: - influxdb networks: - netpulse-network volumes: influxdb-data: influxdb-config: grafana-data: netpulse-state: networks: netpulse-network: driver: bridge