Setup Glances + Influxdb + Grafana to monitor performance on Ubuntu

Peter Xie
4 min readSep 6, 2019

Glances + Influxdb + Grafana are a good combination to monitor Linux server performance stats. I will show how to set it up on Ubuntu as an example.

These three components work together as below.

  • Glances
    A terminal system monitoring tool written in Python. It works like Linux top command but shows more stats and supports export stats to external databases like Influxdb.
  • Influxdb
    One of the popular time-series databases.
  • Grafana
    Dashboard display for time-series analytics data.

All of them are open source.

Installation

It is tedious and a bit tricky to install and integrate these three components. So I wrote a shell script to automate it, [github link]. You just need to run one command from Ubuntu terminal.

wget https://raw.githubusercontent.com/peterjpxie/glances_influxdb_grafana/master/glances_install.sh && sudo -H sh -x glances_install.sh

It automates the tasks as follows:

  • Glances
    Install glances and required packages bottle and influxdb client.
    Create config file /etc/glances/glances.conf, which defines the Influxdb database name as ‘glances’.
  • Influxdb
    Install Influxdb.
    Create a database named as ‘glances’.
    Enable service startup on boot-up.
  • Grafana
    Install Grafana.
    Enable service startup on boot-up.
  • Others
    Allow below ports in iptables for remote service access.
    Glances web - optional: TCP 61208
    Influxdb: TCP 8086, 8088
    Grafana: TCP 3000

Note: You need to allow these ports in other firewall settings yourself if there is any, e.g. AWS Networking Firewall.

Once the installation is done, you can verify the services. On the server terminal, e.g. ssh session, type below command:

glances --export influxdb

You should see it displays top-like stats as below. And it will export the stats to influxdb in the meantime.

To verify Grafana, open a web browser, and enter URL as http://<your server ip>:3000/. You should be able to see a login page.
If it does not work, first check if Grafana service is running as below.

# systemctl status grafana-server
grafana-server.service - Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-09-04 17:37:45 AEST; 2 days ago
Docs: http://docs.grafana.org
Main PID: 969 (grafana-server)
Tasks: 10
Memory: 39.3M
CPU: 36.762s
CGroup: /system.slice/grafana-server.service
└─969 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --pac

Try to start the service by systemctl start grafana-server if it is not running. Otherwise, it must be firewall settings.

Configure Dashboards

Let glances --export influxdb run for some time, e.g. 5 minutes, so that you have data to display in Grafana dashboards. And Grafana will display the real-time stats as well.

Login Grafana with http://<your server ip>:3000/, and enter default username admin and password admin. You will see a home page as below.

We need to select a data source and pick some stats data to display.

Step 1: Add data source

Click ‘Add data source’ from home page, and select source type ‘InfluxDB’. You will see data source settings as below.

Change only these fields:

  • URL: http//<your server ip>:8086
    Note that you should provide server IP address or remotely accessible hostname instead of localhost, unless you are testing in your local PC, otherwise you will get bad gateway error.
  • Database: glances
  • Username / Password: root / root

Click Save & Test. Once it is passed, go back to the home page and continue step 2.

Step 2: New dashboard

Click ‘New dashboard’ from home page, and select ‘Add Query’.

Then you can pick some stats data to display in a dashboard. For instance, we want to display CPU user usage.

  1. In FROM, select a data table from the drop-down list, e.g., localhost.cpu.
  2. In SELECT, select a data column from the drop-down list, e.g., user for cpu user usage.
  3. Then click ‘Save’.

You can change stats duration in the top-right menu, e.g., Last 1 hour.

Follow the same steps, you can create multiple panels in one dashboard, or multiple dashboards. Check Grafana website for more detail.

Thanks for reading.

--

--