dockerreverse-proxytraefiknetdata

traefik configuration for netdata on docker


I am struggling configuring traefik:v2.6 so I can access a self-hosted netdata instance running on docker. This is my compose file:

version: "3"
services:
  netdata:
    image: netdata/netdata
    volumes:
      - "netdataconfig:/etc/netdata"
      - "netdatalib:/var/lib/netdata"
      - "netdatacache:/var/cache/netdata"
      - "/etc/passwd:/host/etc/passwd:ro"
      - "/etc/group:/host/etc/group:ro"
      - "/proc:/host/proc:ro"
      - "/sys:/host/sys:ro"
      - "/etc/os-release:/host/etc/os-release:ro"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.netdata.rule=Host(`netdata.$myserver`)"
      - "traefik.http.services.netdata.loadbalancer.server.port=19999"
      - "traefik.http.routers.netdata.entrypoints=http"
      - "traefik.docker.network=proxy"
    restart: unless-stopped
    cap_add:
      - SYS_PTRACE
    security_opt:
      - apparmor:unconfined
    networks:
      - proxy
volumes:
  netdataconfig:
  netdatalib:
  netdatacache:
networks:
  proxy:
    external: true

When I try to access netdata via netdata.$myserver I see the backdrop only but no dashboard:

netdata_without_dashboard

Checking developer settings in Firefox reveal the following message:

Loading failed for the <script> with source “http://netdata.$myserver/dashboard-react.js”. [netdata.$myserver:16:1](http://netdata.$myserver/)
Uncaught ReferenceError: NETDATA is not defined
    225 main.js:435
    p (index):16
    566 main.7d1bdca1.chunk.js:2
    p (index):16
    324 main.7d1bdca1.chunk.js:2
    p (index):16
    f (index):16
    e (index):16
    <anonymous> main.7d1bdca1.chunk.js:2

The documentation has templates for several reverse proxy configurations, but I cannot translate them into settings I might have missed for traefik.

I tried adding a && Path('/netdata') to the rule traefik.http.routers.netdata.rule=Host('netdata.$myserver')" but there was no difference. The traefik dashboard does not show any errors related to netdata. What am I missing here?

Edit: Issue had nothing to do with traefik but netdata version. This started to work without any changes to my config after netdata update to 1.40.


Solution

  • If you use a Subpath like /netdata you have to call the directory with a slash at the end, then it will work.

     labels:
       - "traefik.enable=true"
       - "traefik.http.routers.netdata.entrypoints=web"
       - "traefik.http.routers.netdata.rule=Host(`yourdomain`) && PathPrefix(`/netdata`)"
       - "traefik.http.routers.netdata.service=netdata"
       - "traefik.http.services.netdata.loadbalancer.server.port=19999"
       - "traefik.http.routers.netdata.middlewares=netdatapathstrip"
       - "traefik.http.middlewares.netdatapathstrip.stripprefix.prefixes=/netdata"
    

    I can reach the dashboard under http://yourdomain/netdata/ If I call http://yourdomain/netdata I get the same behaviour as you mentioned.