Post

Glances Install - Debian/Ubuntu

Glances is a cross-platform monitoring tool which aims to present a large amount of monitoring information through a curses or Web based interface. The information dynamically adapts depending on the size of the user interface.

You need to have python3 and pip3 installed. So, depending on your distro, you may need to use a different package manager for this.

Install Python3

Make sure your server has all the latest package updates.

1
sudo apt update && sudo apt upgrade -y

Next, we’ll install python3 with:

1
sudo apt install python3 -y

After that completes, we’ll install pip3 with:

1
sudo apt install python3-pip

Now that those are installed, we need to install Glances and Bottle (which will allow Glances to run as a web server).

Install Glances and Bottle

Use the following pip3 commands to install Glances and Bottle:

1
pip3 install bottle

If you get an error, try it with sudo like:

1
sudo pip3 install bottle

Now, do the same, but for Glances:

1
pip3 install glances

and again, if you needed sudo for Bottle, you’ll need it for Glances, so do:

1
sudo pip3 install glances

Once those are finished installing, you can test that glances works by running the command:

1
glances

in your terminal. You should see a page full of information about your system show up.

You can stop Glances with the CTRL + C key combination.

Next, you can make sure Bottle is working and run glances in web-server mode with the command:

1
glances -w

You’ll see some output on the terminal, and should have something like Glances Web User Interface started on http://0.0.0.0:61208/ on the screen.

Now, open a browser and go to

1
http://localhost:61208

Or use the ip address of the machine you are working on:

1
http://192.168.1.x:61208

Of course, using the correct private IP of the machine.

You should see a nice view of Glances; almost exactly as it looked in the terminal.

Now you can stop that process in the terminal with CTRL + C, and we need to turn that into a service that will run automatically, even after we reboot the machine.

Create the Glances Service

We’ll be adding a new file to /etc/systemd/system/ called glancesweb.service

So in a terminal window do the following:

1
sudo nano /etc/systemd/system/glancesweb.service

This will open a text editor in your terminal, and it should be empty.

Use the following code to start off:

1
2
3
4
5
6
7
8
[Unit]
Description = Glances in Web Server Mode
After = network.target

[Service]
ExecStart = /usr/local/bin/glances  -w  -t  5

[Install]

If you are running as root, this should work, but we need to make sure glances is running from the path we expect, which is currently /usr/local/bin/. To find this out, save the file with CTRL + O, then press Enter to confirm, then use CTRL + X to exit the nano editor.

In the terminal, do the command:

1
which glances

You should get output like:

1
/usr/local/bin/glances

but, if you aren’t running as root during the install you may get something like:

1
/home/<your usre>/.local/bin/glances

Whatever you get, highlight it, right click, select copy, and then we’ll open the nano editor back up with:

1
sudo nano /etc/systemd/sysetm/glancesweb.service

On that line starting with ExecStart, make sure to remove the path (if it’s different from what you got with the which glances command, and replace it with what you copied.

In my case, I would make it look like

1
2
[Service]
ExecStart = /home/<your usre>/.local/bin/glances -w -t 5

Now, because it’s running from my home directory, I need to add one more line just below this one. If you are running from the /usr/local/bin directory, you do not need this line.

1
User = <your user>

so for me, the file looks like:

1
2
3
[Service]
ExecStart = /home/brian/.local/bin/glances -w -t 5
User = gizzmo

Yours should have your username of course.

Now, save the file with CTRL + O, then press Enter to confirm, and use CTRL + X to exit.

Next, we need to start and enable our service.

We do the following commands to do this:

1
2
sudo systemctl start glances.service
sudo systemctl enable glances.service

As long as you don’t get any errors after each of those, you can check the status with

1
sudo systemctl status glances

You should see a row in the output near the top that shows active. If you see failed, you need to recheck the glancesweb.service file, and make sure you have everything correct.

Now that it’s running, you can again go to the ip address of:

1
http://<local ip>:61208

and view your glances in the web browser.

This post is licensed under CC BY 4.0 by the author.