mohsenasm/swarm-dashboard

By mohsenasm

Updated about 1 month ago

A Simple Monitoring Dashboard for Docker Swarm Cluster

Image
Developer tools
Monitoring & observability
1

1M+

mohsenasm/swarm-dashboard repository overview

Continuing the work of charypar/swarm-dashboard.

See the latest readme at: https://github.com/mohsenasm/swarm-dashboard


Swarm Dashboard

A simple monitoring dashboard for Docker in Swarm Mode.

Publish Docker image

Swarm Dashboard shows you all the tasks running on a Docker Swarm organized by service and node. It provides a space-efficient visualization and works well at a glance. You can use it as a simple live dashboard of the state of your Swarm.

It also shows the CPU/Memory/Disk usage of your swarm node and containers.

Usage

The dashboard needs to be deployed on one of the swarm managers. You can configure it with the following Docker compose file:

# compose.yml
version: "3"

services:
  swarm-dashboard:
    image: mohsenasm/swarm-dashboard:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 8080:8080
    environment:
      TZ: "your_timezone"
      ENABLE_AUTHENTICATION: "false"
      ENABLE_HTTPS: "false"
      NODE_EXPORTER_SERVICE_NAME_REGEX: "node-exporter"
      CADVISOR_SERVICE_NAME_REGEX: "cadvisor"
    deploy:
      placement:
        constraints:
          - node.role == manager
  
  node-exporter:
    image: quay.io/prometheus/node-exporter:v1.6.1
    volumes:
      - '/:/host:ro'
    command:
      - '--path.rootfs=/host'
    deploy:
      mode: global

  cadvisor:
    image: gcr.io/cadvisor/cadvisor:v0.47.2
    volumes:
      - /:/rootfs:ro
      - /var/run:/var/run:rw
      - /sys:/sys:ro
      - /var/lib/docker/:/var/lib/docker:ro
      - /dev/disk/:/dev/disk:ro
    deploy:
      mode: global

and deploy with

$ docker stack deploy -c compose.yml sd

Note that the usage of node-exporter and cadvisor are optional, to fetch node CPU/Memory/Disk usage and containers' CPU/Memory usage respectively. If you don't specify NODE_EXPORTER_SERVICE_NAME_REGEX and CADVISOR_SERVICE_NAME_REGEX envs, the default is not using this feature, because of backward compatibility.

Advance Usage

List of environment variables for more customization:

Enviroment VariblesExampleConsidration
PORT8080HTTP / HTTPS port.
PATH_PREFIX/prefix_pathAll HTTP and WebSocket connections will use this path as a prefix.
TZAsia/TehranSet the timezone for the time reported in the dashboard.
SHOW_TASK_TIMESTAMPfalsetrue by default.
ENABLE_AUTHENTICATIONtruefalse by default.
AUTHENTICATION_REALMMyRealmUse this env if ENABLE_AUTHENTICATION is true.
USERNAMEadminUse this env if ENABLE_AUTHENTICATION is true.
PASSWORDsupersecretUse this env if ENABLE_AUTHENTICATION is true.
ENABLE_HTTPStruefalse by default
LEGO_PATH/lego-filesUse this env if ENABLE_HTTPS is true. Lego is used to create the SSL certificates. Create a named volume for this path to avoid the creation of a new certificate on each run.
HTTPS_HOSTNAMEswarm-dashboard.example.comUse this env if ENABLE_HTTPS is true.
LEGO_NEW_COMMAND_ARGS--accept-tos --email=[email protected] --domains=swarm-dashboard.example.com --dns cloudflare runUse this env if ENABLE_HTTPS is true.
LEGO_RENEW_COMMAND_ARGS--accept-tos --email=[email protected] --domains=swarm-dashboard.example.com --dns cloudflare renewUse this env if ENABLE_HTTPS is true.
CLOUDFLARE_EMAIL[email protected]You can use any DNS provider that Lego supports.
CLOUDFLARE_API_KEYyourprivatecloudflareapikeyYou can use any DNS provider that Lego supports.
DOCKER_UPDATE_INTERVAL5000Refresh interval in ms.
METRICS_UPDATE_INTERVAL60000Refresh interval in ms.
NODE_EXPORTER_SERVICE_NAME_REGEXnode-exporterUse this env to enable node-exporter integration.
NODE_EXPORTER_INTERESTED_MOUNT_POINT/rootfsYou may need this config if you have not specified --path.rootfs for node-exporter.
NODE_EXPORTER_PORT9100
CADVISOR_SERVICE_NAME_REGEXcadvisorUse this env to enable cadvisor integration.
CADVISOR_PORT8080

Security

  • We redact docker event data before sending them to the client. The previous version was sending the whole docker event data, including environment variables (someone might have stored some passwords in them, by mistake!). So, please consider using the newer version.

  • Using the ENABLE_AUTHENTICATION environment variable, there is an option to use Basic Auth. The WebSocket server will close the connection if it does not receive a valid authentication token. See the example in the above section for more info.

  • Using the ENABLE_HTTPS environment variable, there is an option to use HTTPS and WSS. We have Let’s Encrypt integration with the DNS challenge. See the example in the above section for more info.

Production use

There are two considerations for any serious deployment of the dashboard:

  1. Security - the dashboard node.js server has access to the docker daemon unix socket and runs on the manager, which makes it a significant attack surface (i.e. compromising the dashboard's node server would give an attacker full control of the swarm)
  2. The interaction with docker API is a fairly rough implementation and is not very optimized. The server polls the API every 1000 ms, publishing the response data to all open WebSockets if it changed since last time. There is probably a better way to look for changes in the Swarm that could be used in the future.

Rough roadmap

  • Show more service details (published port, image name, and version)
  • Node / Service / Task details panel

Both feature requests and pull requests are welcome. If you want to build/test the code locally, see commands.md in the test-cluster directory.

Prior art

Contributors

  • Mohammad-Mohsen Aseman-Manzar (current maintainer) - code, docs
  • Viktor Charypar (previous repo owner) - code, docs
  • Clementine Brown - design

Tag summary

Content type

Image

Digest

sha256:20342590d

Size

79.2 MB

Last updated

about 1 month ago

docker pull mohsenasm/swarm-dashboard