How to Install Graphite and Graphite Web on Ubuntu 20.04

Graphite is a free and open-source monitoring tool to store numeric time-series data and its graph in real-time.

Graphite doesn't collect data by itself, instead it receives data from other tools. As soon as Graphite receives data it can create graphs in the webapp.

In this tutorial, we learn how to install Graphite and Graphite Web on Ubuntu 20.04 using docker. The easiest way to have a running Graphite instance is by using docker.

How does Graphite work?

The overview of the Graphite architecture shows that it consists of three software components:

  • Carbon: Twisted daemon that passively listens to time series data for data collection.
  • Whisper: simple database library for storing time series data
  • Graphite WebApp: Django WebApp which renders graphics on demand using Cairo.

The application sends the data to Graphite's processing backend, Carbon, which stores the data in Graphite's database Whisper. Then, the data can be viewed through the Graphite web interface, Graphite Web App.

Step1: Install Docker on Ubuntu

First, we will install Docker on Ubuntu. Using Docker you can run Grapgitue in seconds.

To install docker, you will need to install some pre-requisites:

$ sudo apt install apt-transport-https ca-certificates curl software-properties-common

Now let's add the GP key of the docker repository:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Now add Docker to the APT sources. It will automatically update the cache.

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Now install docker using the following command:

$ sudo apt install docker-ce

Add the user to the docker group so that he can use the docker command without sudo privileges:

$ sudo usermod -aG docker username

Then exit and log in again to have the action taking effect

Step 2: Run graphite with docker

It's very fast to run graphite with docker. This time it will need some other components than the defaults one we have seen earlier:

  • Nginx: reverse proxies the graphite dashboard
  • Graphite: front-end dashboard
  • Carbon: back-end
  • Statsd: UDP based back-end proxy

You will also need to check if the different ports that graphite needs will be available. Also, during the process, a port mapping will be done between the host and the container so you can change some mapping configuration on your side if it doesn't suit your actual configuration. You can have more information on the official Github repo of graphite.

HostContainerService
8080nginx
20032003carbon receiver - plaintext
20042004carbon receiver - pickle
20232023carbon aggregator - plaintext
20242024Carbon aggregator - pickle
80808080Graphite internal gunicorn port (without Nginx proxying).
81258125statsd
81268126statsd admin

Run nginx docker

In our case, we will run an independent container as our Nginx reverse proxy.

$ docker run -d --name nginx -p 80:80 -p 443:443 -v /etc/nginx/htpasswd:/etc/nginx/htpasswd -v /etc/nginx/vhost.d:/etc/nginx/vhost.d:ro -v /etc/nginx/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro etopian/nginx-proxy

It will help us to redirect all the default HTTP traffic to HTTPS when you integrate your certificates. You should notice the mapped volume to integrate your certificates which is /etc/nginx/certs

Now open the port 80 and 443 on the firewall:

$ sudo ufw allow 80,443/tcp

Step 3: Graphite - Integrate your SSL certificate to nginx

We are considering that you already possess your SSL certificates. You will have to copy it in the mapped volume configured for this case in Nginx. We will name our key and certificate as below:

  • domain.com.crt
  • domain.com.key

And we will copy the two files in the mapped volume. Copy the certificate

$ cp websitefortesting.com.crt /etc/nginx/certs

Copy the key

$ cp websitefortesting.com.key /etc/nginx/certs

Run graphite

To run graphite, we will also use the docker run command with some options. In our case, we will indicate the domain name our of service with the parameter -e VIRTUAL_HOST=domain.com while starting it

$ docker run -d\
  --name graphite\
  --restart=always\
  -e VIRTUAL_HOST=websitefortesting.com\
  -p 2003-2004:2003-2004\
  -p 2023-2024:2023-2024\
  -p 8125:8125/udp\
  -p 8126:8126\
  graphiteapp/graphite-statsd

As you can see, there is no need to map port 80 of Nginx as it's already running. Now try accessing graphite by the URL https://domain.com

graphite web interface

You can have a look on statsd.

graphite statsd

The default login username of Graphite is root and login with the root password.

You should change the default password of the root profile to make it more secure by using at https://domain.com/admin/password_change/

graphite change password

You can access it with your new password.

Conclusion

In this tutorial, we learned how to run graphite on Ubuntu 20.04 by using docker. You can now easily monitor and graphs numeric time-series data.

Leave a Comment