Combining Supervisor and nginx-proxy (docker) to remotely monitor Glances
Feb 12, 2021
I wrote a post a while back about nginx-proxy and how I was using it to resolve local DNS records. Today I decided I wanted to be able to monitor my server remotely using glances running over Supervisor and utilizing glances' internal webserver.
I could be running glances
inside a docker container and exposing the docker socket to monitor most of the metrics but that would mean I'd lose useful disk and network information. So since this isn't going to be running inside a container I needed a somewhat creative way to add it to the local
network.
Install glances and configure Supervisor:
1 2
$ sudo apt-get install -y supervisor $ sudo vi /etc/supervisor/conf.d/glances.conf
Configure the program you wish to run through Supervisor:
# /etc/supervisor/conf.d/glances.conf
[program:glances]
command=/usr/bin/glances -w
autostart=true
autorestart=true
Load and start the configured program:
1 2
$ sudo supervisorctl reread $ sudo supervisorctl update
Confirm everything is running:
1 2
$ sudo supervisorctl status glances RUNNING pid 647763, uptime 0:35:01
Now the creative part, adding it to the nginx-proxy
network. To be able to do this we are going to make use of a docker image called docker-host. Simply explained this image allows you to forward TCP and UDP traffic from within the container to the docker host.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
version: "3" services: proxy: image: jwilder/nginx-proxy:alpine environment: DEFAULT_HOST: status.local ports: - 80:80 volumes: - /var/run/docker.sock:/tmp/docker.sock restart: always glances: image: qoomon/docker-host expose: - 61208 environment: VIRTUAL_HOST: status.local restart: always cap_add: [ 'NET_ADMIN', 'NET_RAW' ]
By giving the glances
service access to the docker host by giving it the desired Linux capabilities we can expose the 61208
port which is being used by the glances
webserver and forward all traffic coming in from status.local
to the correct destination.
Now whenever I visit http://status.local I'm able to monitor my server using the familiar glances
interface remotely without having to ssh
each time.