Combining Supervisor and nginx-proxy (docker) to remotely monitor Glances

Fri 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$ sudo apt-get install -y supervisor 2$ sudo vi /etc/supervisor/conf.d/glances.conf

Configure the program you wish to run through Supervisor:

# /etc/supervisor/conf.d/glances.conf
command=/usr/bin/glances -w

Load and start the configured program:

1$ sudo supervisorctl reread 2$ sudo supervisorctl update

Confirm everything is running:

1$ sudo supervisorctl status 2glances 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.

1version: "3" 2 3services: 4 proxy: 5 image: jwilder/nginx-proxy:alpine 6 environment: 7 DEFAULT_HOST: status.local 8 ports: 9 - 80:80 10 volumes: 11 - /var/run/docker.sock:/tmp/docker.sock 12 restart: always 13 14 glances: 15 image: qoomon/docker-host 16 expose: 17 - 61208 18 environment: 19 VIRTUAL_HOST: status.local 20 restart: always 21 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.