Skip to content

Commit

Permalink
Merge pull request #27 from mohsenasm/dev_stats
Browse files Browse the repository at this point in the history
Show container / node stats
  • Loading branch information
mohsenasm authored Oct 21, 2023
2 parents 0ec0912 + eb59fad commit 36730aa
Show file tree
Hide file tree
Showing 28 changed files with 798 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
push:
branches:
- 'master'
- 'dev_security'
- 'dev_stats'
tags:
- 'v*'

Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ RUN yarn install --production

# elm doesn't work under alpine 6 or 8
FROM node:10.16.0-buster-slim AS elm-build
WORKDIR /home/node/app
RUN npm install --unsafe-perm -g [email protected] --silent
RUN apt-get update; apt-get install -y netbase
COPY elm-package.json ./
WORKDIR /home/node/app/elm-client
COPY ./elm-client/elm-package.json .
RUN elm package install -y
COPY . .
COPY ./elm-client/ /home/node/app/elm-client/
RUN elm make Main.elm --output=client/index.js

FROM base AS release
Expand All @@ -28,11 +28,12 @@ RUN wget -O lego_v4.14.2_linux_amd64.tar.gz https://github.com/go-acme/lego/rele
ENV LEGO_PATH=/lego-files

COPY --from=dependencies /home/node/app/node_modules node_modules
COPY --from=elm-build /home/node/app/client/ client
COPY --from=elm-build /home/node/app/elm-client/client/ client
COPY server server
COPY server.sh server.sh
COPY crontab /var/spool/cron/crontabs/root

# ENV PORT=8080
# HEALTHCHECK --interval=5s --timeout=3s \
# CMD curl --fail http://localhost:$PORT/_health || exit 1
# HEALTHCHECK --interval=5s --timeout=3s \
Expand Down
108 changes: 69 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,95 @@ A simple monitoring dashboard for Docker in Swarm Mode.

![Example Dashboard](./swarm.gif)

## About
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.

Swarm dashboard shows you all the tasks running on a Docker Swarm organized
by service and node. It provides a visualization that's space-efficient
and works well at a glance.
It also shows the CPU/Memory/Disk usage of your swarm node and containers.

You can use it as a simple live dashboard of the state of your Swarm.
## Usage

The Dashboard has a node.js server which streams swarm updates to an Elm client
over a WebSocket.

### Prior art

* Heavily inspired by [Docker Swarm Visualiser](https://github.com/dockersamples/docker-swarm-visualizer)

## Running

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

```yml
# compose.yml
version: "3"

services:
dashboard:
image: mohsenasm/swarm-dashboard
swarm-dashboard:
image: mohsenasm/swarm-dashboard:dev_stats
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- lego-files:/lego-files
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 8081:8081
- 8080:8080
environment:
PORT: 8081
PORT: 8080
ENABLE_AUTHENTICATION: "false"
# ENABLE_AUTHENTICATION: "true"
# AUTHENTICATION_REALM: "KuW2i9GdLIkql"
# USERNAME: "admin"
# PASSWORD: "supersecret"
ENABLE_HTTPS: "false"
# ENABLE_HTTPS: "true"
# HTTPS_HOSTNAME: "example.com"
# LEGO_NEW_COMMAND_ARGS: "--accept-tos [email protected] --domains=example.com --dns cloudflare run"
# LEGO_RENEW_COMMAND_ARGS: "--accept-tos [email protected] --domains=example.com --dns cloudflare renew"
# CLOUDFLARE_EMAIL: "[email protected]"
# CLOUDFLARE_API_KEY: "yourprivatecloudflareapikey"
NODE_EXPORTER_SERVICE_NAME_REGEX: "node-exporter"
CADVISOR_SERVICE_NAME_REGEX: "cadvisor"
deploy:
replicas: 1
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

volumes:
lego-files:
cadvisor:
image: gcr.io/cadvisor/cadvisor
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 svc
$ 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 need this feature, make sure to remove `NODE_EXPORTER_SERVICE_NAME_REGEX` and `CADVISOR_SERVICE_NAME_REGEX` envs.

## Advance Usage

List of environment variables for more customization:

| Enviroment Varibles | Example | Considration |
|--------------------------------------|-------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| PORT | 8080 | HTTP / HTTPS port |
| ENABLE_AUTHENTICATION | true | false by default |
| AUTHENTICATION_REALM | MyRealm | Use this env if ENABLE_AUTHENTICATION is `true`. |
| USERNAME | admin | Use this env if ENABLE_AUTHENTICATION is `true`. |
| PASSWORD | supersecret | Use this env if ENABLE_AUTHENTICATION is `true`. |
| ENABLE_HTTPS | true | false by default |
| LEGO_PATH | /lego-files | Use 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_HOSTNAME | swarm-dashboard.example.com | Use this env if ENABLE_HTTPS is `true`. |
| LEGO_NEW_COMMAND_ARGS | --accept-tos --email=[email protected] --domains=swarm-dashboard.example.com --dns cloudflare run | Use this env if ENABLE_HTTPS is `true`. |
| LEGO_RENEW_COMMAND_ARGS | --accept-tos --email=[email protected] --domains=swarm-dashboard.example.com --dns cloudflare renew | Use this env if ENABLE_HTTPS is `true`. |
| CLOUDFLARE_EMAIL | [email protected] | You can use any [DNS provider that Lego supports](https://go-acme.github.io/lego/dns/). |
| CLOUDFLARE_API_KEY | yourprivatecloudflareapikey | You can use any [DNS provider that Lego supports](https://go-acme.github.io/lego/dns/). |
| DOCKER_UPDATE_INTERVAL | 1000 | Refresh interval in ms. |
| METRICS_UPDATE_INTERVAL | 5000 | Refresh interval in ms. |
| NODE_EXPORTER_SERVICE_NAME_REGEX | node-exporter | Use this env to enable `node-exporter` integration. |
| NODE_EXPORTER_INTERESTED_MOUNT_POINT | /rootfs | You may need this config if you have not specified `--path.rootfs` for `node-exporter`. |
| NODE_EXPORTER_PORT | 9100 | |
| CADVISOR_SERVICE_NAME_REGEX | cadvisor | Use this env to enable `cadvisor` integration. |
| CADVISOR_PORT | 8080 | |


## 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.
Expand Down Expand Up @@ -93,12 +120,15 @@ There are two considerations for any serious deployment of the dashboard:

* Show more service details (published port, image name, and version)
* Node / Service / Task details panel
* Show node / task resources (CPU & Memory)
* Improve security for potential production use

Both feature requests and pull requests are welcome
Both feature requests and pull requests are welcome.

### Prior art

* Heavily inspired by [Docker Swarm Visualiser](https://github.com/dockersamples/docker-swarm-visualizer)

## Contributors

* Viktor Charypar (owner, BDFL) - code, docs
* Mohammad-Mohsen Aseman-Manzar (current maintainer) - code, docs
* Viktor Charypar (previous repo owner) - code, docs
* Clementine Brown - design
1 change: 1 addition & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
# LEGO_RENEW_COMMAND_ARGS: "--accept-tos [email protected] --domains=example.com --dns cloudflare renew"
# CLOUDFLARE_EMAIL: "[email protected]"
# CLOUDFLARE_API_KEY: "yourprivatecloudflareapikey"
NODE_EXPORTER_SERVICE_NAME_REGEX: "node-exporter"
deploy:
replicas: 1
update_config:
Expand Down
64 changes: 53 additions & 11 deletions Components.elm → elm-client/Components.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ statusString state desiredState =


task : Service -> AssignedTask -> Html msg
task service { status, desiredState, containerSpec, slot } =
task service { status, desiredState, containerSpec, slot, info } =
let
classes =
[ ( status.state, True )
Expand All @@ -32,12 +32,39 @@ task service { status, desiredState, containerSpec, slot } =

Nothing ->
""

cpuInfo =
case info.cpu of
Just s ->
[
div [ class "tag left" ] [ text s ]
]

Nothing ->
[]

memoryInfo =
case info.memory of
Just s ->
[
div [ class "tag right" ] [ text s ]
]

Nothing ->
[]
in
li [ classList classes ]
[ text (service.name ++ slotLabel slot)
, br [] []
, text (statusString status.state desiredState)
]
(List.concat [
cpuInfo
, (List.concat [
memoryInfo
, [ text (service.name ++ slotLabel slot)
, br [] []
, text (statusString status.state desiredState)
]
])
])



serviceNode : Service -> TaskIndex -> Node -> Html msg
Expand Down Expand Up @@ -77,14 +104,29 @@ node node =

nodeRole =
String.join " " [ node.role, iff leader "(leader)" "" ]

info =
case node.info of
Just s ->
[
br [] []
, text (s)
]

Nothing ->
[]
in
th [ classList classes ]
[ strong [] [ text node.name ]
, br [] []
, text nodeRole
, br [] []
, text node.status.address
]
(List.concat [
[
strong [] [ text node.name ]
, br [] []
, text nodeRole
, br [] []
, text node.status.address
]
, info
])


swarmHeader : List Node -> List Network -> Html msg
Expand Down
File renamed without changes.
Loading

0 comments on commit 36730aa

Please sign in to comment.