Real-time monitoring of Linux

Surely you use the “top” or even “htop” tool to make it look more colorful when analyzing the state of your server’s resources, but this only analyzes the processes…

What if on the same screen we could see the processes, resources, network traffic and disk usage? The solution is in the tool is Glances.

This tutorial has been created on a Clouding.io VPS. You can create your own VPS from 3€/month.

In addition, you have the possibility to create your VPS with the WordPress image in one click.

PARTNERSHIP

Installation

There are several ways to install it. The official one is:

wget -O- https://bit.ly/glances | /bin/bash

Although, for example in Ubuntu you have

apt -y install glances

Execution

Once installed you can run it and see the information:

glances

That would show something like this:

Features and tricks

This tool is very flexible and has a thousand systems to extract the data from the machine.

For example, we can show on the screen in a JSON some data:

glances --stdout cpu.user,mem.used,load

And who says JSON, says CSV:

glances --stdout-csv now,cpu.user,mem.used,load

Use as a service

Something interesting is that it can be accessed from outside to collect information from each machine, but for this we should start the application as a service so that it is always available. We can do this by creating a service.

The first thing we will do is create the service file:

vim /etc/systemd/system/glances.service

And we’ll include this:

[Unit]
Description=Glances
After=network.target

[Service]
ExecStart=/usr/bin/glances -w
Restart=on-abort
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Once created, we must activate the service (so that it is activated when the machine starts).

systemctl enable glances.service

And then we will activate it.

systemctl start glances.service

This will, by default, activate a web server by port 61208, from where we can collect the data.

If you want to change the port or limit access to certain IPs, you can change this line:

ExecStart=/usr/bin/glances -w -p 8080 -B 10.0.0.2

With this only the client 10.0.0.2 could access the data by port 8080.

Configuration

If we want to apply any configuration we can do it in the folder /etc/glances/.

By default there is already a configuration file in which comes a lot of predefined information that we can edit.

vim /etc/glances/glances.conf

Although perhaps the most interesting is the possibility of exporting the information to other services such as Elasticsearch, JSON, prometheis or RESTful. The list is quite extensive.


About this document

This document is regulated by the EUPL v1.2 license, published in WP SysAdmin and created by Javier Casares. Please, if you use this content in your website, your presentation or any material you distribute, remember to mention this site or its author, and having to put the material you create under EUPL license.