Install Graphite and Graphite-Web on Ubuntu 20.04 using Docker

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose

Welcome to our guide, which captures the installation of Graphite and Graphite-Web on Ubuntu 20.04. Graphite is an open source monitoring platform designed to provide high availability and support data visualization. How users use Graphite is to collect the digital time series data to be drawn by writing an application, and then send it to the processing backend of Graphite. carbon, Store the data in Graphite’s dedicated database.

Graphite will:

  1. Store digital time series data
  2. Graph this data on demand

There are many tool A tool that helps you collect data and send it to Graphite. Even if some code is often needed, send data Graphite is very simple. Graphite is designed for horizontal scalability on the front and back ends, which means you can simply add more computers to the mix for greater throughput.

Graphite contains 3 software components:

  1. carbon -A Twisted A daemon that listens to time series data
  2. whisper -A simple database library for storing time series data (design similar to RRD)
  3. Graphite web -A Django A webapp that renders graphics on demand using the following commands Cairo

This article will show you how to easily have a running instance of Graphite Server on Ubuntu 20.04 Server

Install Graphite and Graphite-Web on Ubuntu 20.04 using Docker

The easiest and fastest way to run Graphite on Ubuntu 20.04 is to use a Docker container. To do this, all you need to do is install Docker, pull the container image and start the graphite container.

Step 1: Update the system

First update and upgrade the system.

sudo apt update
sudo apt upgrade -y

After the upgrade is complete, reboot the system.

sudo reboot

Step 2: Install the Docker container engine

After the system restarts, log in and install some dependencies.

sudo apt update
sudo apt -y install vim apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Import the Docker APT repository GPG key.

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

Add the Docker CE repository to the Ubuntu computer.

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

Install Docker CE on Ubuntu 20.04 Server.

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

Add your user account to the docker group.

sudo usermod -aG docker $USER
newgrp docker

Verify the installation by checking the Docker version:

$ docker info
Client:
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 19.03.13
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8fba4e9a7d01810a393d5d25a3621dc101981175
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-48-generic
 Operating System: Ubuntu 20.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.894GiB
 Name: ubuntu
 ID: ZJXE:T7RY:FSAV:CRBN:Q6Y7:YQQA:2ELU:VH25:P6PJ:6X6B:3WTC:EU2F
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Before proceeding, please confirm that the service is running:

$ systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-10-11 03:02:10 CEST; 1min 12s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 2663 (dockerd)
      Tasks: 8
     Memory: 35.7M
     CGroup: /system.slice/docker.service
             └─2663 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.495871164+02:00" level=warning msg="Your kernel does not support cgroup rt runtime"
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.496038020+02:00" level=warning msg="Your kernel does not support cgroup blkio weight"
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.496232070+02:00" level=warning msg="Your kernel does not support cgroup blkio weight_device"
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.497045530+02:00" level=info msg="Loading containers: start."
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.667666503+02:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0>
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.781078393+02:00" level=info msg="Loading containers: done."
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.835604534+02:00" level=info msg="Docker daemon" commit=4484c46d9d graphdriver(s)=overlay2 version>
Oct 11 03:02:10 ubuntu dockerd[2663]: time="2020-10-11T03:02:10.836601759+02:00" level=info msg="Daemon has completed initialization"
Oct 11 03:02:10 ubuntu systemd[1]: Started Docker Application Container Engine.

Step 3: Run Graphite on Ubuntu 20.04 in a Docker container

After installing and running the docker engine, you can start Graphite and Statsd docker containers.We will use the official Graphite’s Docker repo:

Download the latest Docker image.

$ docker pull  graphiteapp/graphite-statsd
Using default tag: latest
latest: Pulling from graphiteapp/graphite-statsd
df20fa9351a1: Pull complete
f9a569415da5: Pull complete
8f0c7d0dc99e: Pull complete
700de820209a: Pull complete
Digest: sha256:04a0037cc2ae7cc189b81fb38fbdc914fe269b861108821bea1ed776878334de
Status: Downloaded newer image for graphiteapp/graphite-statsd:latest
docker.io/graphiteapp/graphite-statsd:latest

List available images:

$ docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
graphiteapp/graphite-statsd   latest              875c7f22f4cd        2 months ago        628MB

Create a directory on the host system to store data persistently. This can be the mount point of a disk or partition dedicated to storing Graphite data.

sudo mkdir -p /data/graphite/{data,logs,conf,statsd_config}

The image we downloaded includes the following components:

Mapped port

HostContainerService
8080Nginx
Year 2003Year 2003Carbon Receiver-Plain Text
year 2004year 2004Carbon canister-pickled vegetables
20232023Carbon Accumulator-Plain Text
20242024Carbon Accumulator-Pickled
80808080Graphite internal Gunicorn port (no Nginx proxy).
81258125statistics
81268126statsd administrator

The setup of Graphite & Statsd can be complicated. The provided docker image will allow you to run and collect statistics in just a few minutes.

Before running the command, change the time zone to the correct setting.

docker run -d 
 --name graphite 
 --restart=always 
 -p 80:80 
 -p 2003-2004:2003-2004 
 -p 2023-2024:2023-2024 
 -p 8125:8125/udp 
 -p 8126:8126 
 -v /data/graphite/data:/opt/graphite/storage 
 -v /data/graphite/conf:/opt/graphite/conf 
 -v /data/graphite/statsd_config:/opt/statsd/config 
 -v /data/graphite/logs:/var/log 
 -e GRAPHITE_TIME_ZONE='Africa/Nairobi' 
 graphiteapp/graphite-statsd

List the running containers to see if the graphite container is running.

$ docker ps
CONTAINER ID        IMAGE                         COMMAND             CREATED             STATUS              PORTS                                                                                                                                                                       NAMES
4a26c4c0f746        graphiteapp/graphite-statsd   "/entrypoint"       31 seconds ago      Up 29 seconds       0.0.0.0:80->80/tcp, 0.0.0.0:2003-2004->2003-2004/tcp, 2013-2014/tcp, 8080/tcp, 0.0.0.0:2023-2024->2023-2024/tcp, 0.0.0.0:8126->8126/tcp, 8125/tcp, 0.0.0.0:8125->8125/udp   graphite

You can stream the log to check if there are any errors.

$ docker logs -f graphite

Sample output:

,,..
1/10/2020 01:23:58 :: [tagdb] Tagged carbon.aggregator.4a26c4c0f746-a.destinations.127_0_0_1:2004:None.attemptedRelays, carbon.aggregator.4a26c4c0f746-a.bufferedDatapoints in 0.021245479583740234
11/10/2020 01:24:06 :: [listener] MetricLineReceiver connection with 127.0.0.1:57472 established
11/10/2020 01:24:06 :: [listener] MetricLineReceiver connection with 127.0.0.1:57472 closed cleanly
11/10/2020 01:24:08 :: [tagdb] Tagging carbon.agents.4a26c4c0f746-a.errors
11/10/2020 01:24:08 :: [tagdb] Tagged carbon.agents.4a26c4c0f746-a.errors in 0.15246272087097168
11/10/2020 01:24:16 :: [listener] MetricLineReceiver connection with 127.0.0.1:57476 established
11/10/2020 01:24:16 :: [listener] MetricLineReceiver connection with 127.0.0.1:57476 closed cleanly
11/10/2020 01:24:26 :: [listener] MetricLineReceiver connection with 127.0.0.1:57478 established
11/10/2020 01:24:26 :: [listener] MetricLineReceiver connection with 127.0.0.1:57478 closed cleanly
11/10/2020 01:24:26 :: [tagdb] Tagging stats.statsd.graphiteStats.last_flush
11/10/2020 01:24:26 :: [tagdb] Tagged stats.statsd.graphiteStats.last_flush in 0.013707160949707031
11/10/2020 01:24:36 :: [listener] MetricLineReceiver connection with 127.0.0.1:57482 established
11/10/2020 01:24:36 :: [listener] MetricLineReceiver connection with 127.0.0.1:57482 closed cleanly
11/10/2020 01:24:36 :: [tagdb] Tagging stats.timers.view.graphite.tags.views.tagMultiSeries.POST.count_90
11/10/2020 01:24:36 :: [tagdb] Tagged stats.timers.view.graphite.tags.views.tagMultiSeries.POST.count_90 in 0.011429786682128906
11/10/2020 01:24:46 :: [listener] MetricLineReceiver connection with 127.0.0.1:57486 established
11/10/2020 01:24:46 :: [listener] MetricLineReceiver connection with 127.0.0.1:57486 closed cleanly
11/10/2020 01:24:47 :: [tagdb] Tagging carbon.aggregator.4a26c4c0f746-a.whitelistRejects
11/10/2020 01:24:47 :: [tagdb] Tagged carbon.aggregator.4a26c4c0f746-a.whitelistRejects in 0.015319108963012695
11/10/2020 01:24:56 :: [listener] MetricLineReceiver connection with 127.0.0.1:57490 established
11/10/2020 01:24:56 :: [listener] MetricLineReceiver connection with 127.0.0.1:57490 closed cleanly
11/10/2020 01:24:57 :: [tagdb] Tagging carbon.agents.4a26c4c0f746-a.memUsage
11/10/2020 01:24:57 :: [tagdb] Tagged carbon.agents.4a26c4c0f746-a.memUsage in 0.009841442108154297
11/10/2020 01:25:06 :: [listener] MetricLineReceiver connection with 127.0.0.1:57494 established
11/10/2020 01:25:06 :: [listener] MetricLineReceiver connection with 127.0.0.1:57494 closed cleanly
11/10/2020 01:25:07 :: [tagdb] Tagging carbon.agents.4a26c4c0f746-a.creates
11/10/2020 01:25:07 :: [tagdb] Tagged carbon.agents.4a26c4c0f746-a.creates in 0.019759416580200195

By default, statsd listens on UDP port 8125.If you want it to listen on TCP port 8125, you can set environment variables STATSD_INTERFACE to tcp When running the container.

Step 4: Visit the Graphite Web interface

Then, you can use the server IP address or port number and the port on the host that is mapped to container port 80 to access the Graphite Web console:

The default login credentials are:

Username: root
Password: root

Install Graphite and Graphite-Web on Ubuntu 20.04 using Docker

After the first login, please change this login credentials http: // ip-address / admin / auth / user / 1 /. Click “change the password“Link to initiate the root user password change.

Install Graphite and Graphite-Web on Ubuntu 20.04 using Docker

Provide the required new root password and confirm it.

Install Graphite and Graphite-Web on Ubuntu 20.04 using Docker

Now you can log out and return with the new password.

Step 5: Use Systemd to manage graphite containers

To ensure that our container starts when the system boots, let’s create a new Systemd service unit file.

sudo tee /etc/systemd/system/graphite-docker.service<<EOF
[Unit]
Description=Graphite Docker Container
Documentation=https://github.com/graphite-project/docker-graphite-statsd
After=docker.service
Requires=docker.service

[Service]
Type=simple
TimeoutStartSec=0
Restart=on-failure
RestartSec=30s
ExecStartPre=-/usr/bin/docker kill graphite
ExecStartPre=-/usr/bin/docker rm graphite
ExecStartPre=/usr/bin/docker pull graphiteapp/graphite-statsd
ExecStart=/usr/bin/docker run 
            --name graphite 
            --restart=always 
            -p 80:80 
            -p 2003-2004:2003-2004 
            -p 2023-2024:2023-2024 
            -p 8125:8125/udp 
            -p 8126:8126 
            -v /data/graphite/data:/opt/graphite/storage 
            -v /data/graphite/conf:/opt/graphite/conf 
            -v /data/graphite/statsd_config:/opt/statsd/config 
            -v /data/graphite/logs:/var/log 
            graphiteapp/graphite-statsd

SyslogIdentifier=graphite
ExecStop=/usr/bin/docker stop graphite

[Install]
WantedBy=multi-user.target
EOF

Reload system services.

sudo systemctl daemon-reload

The unit file we created should now be recognized.

$ sudo systemctl list-unit-files graphite-docker.service
UNIT FILE               STATE    VENDOR PRESET
graphite-docker.service disabled enabled

1 unit files listed.

Let’s enable the service to start when the system boots.

$ sudo systemctl enable graphite-docker
Created symlink /etc/systemd/system/multi-user.target.wants/graphite-docker.service → /etc/systemd/system/graphite-docker.service.

Terminate the running container to confirm that the service is running.

sudo docker rm -f graphite

If there are no other containers, the ps list should return empty.

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Start the Systemd service.

sudo systemctl start graphite-docker.service

Check service status:

$ systemctl status graphite-docker.service
● graphite-docker.service - Graphite Docker Container
     Loaded: loaded (/etc/systemd/system/graphite-docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-10-11 03:53:48 CEST; 10s ago
       Docs: https://github.com/graphite-project/docker-graphite-statsd
    Process: 16394 ExecStartPre=/usr/bin/docker kill graphite (code=exited, status=1/FAILURE)
    Process: 16410 ExecStartPre=/usr/bin/docker rm graphite (code=exited, status=1/FAILURE)
    Process: 16416 ExecStartPre=/usr/bin/docker pull graphiteapp/graphite-statsd (code=exited, status=0/SUCCESS)
   Main PID: 16428 (docker)
      Tasks: 7 (limit: 2286)
     Memory: 25.1M
     CGroup: /system.slice/graphite-docker.service
             └─16428 /usr/bin/docker run --name graphite --restart=always -p 80:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 -v>

Oct 11 03:53:53 ubuntu graphite[16428]: run: carbon: (pid 73) 5s; run: log: (pid 72) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: run: carbon-aggregator: (pid 66) 5s; run: log: (pid 65) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: down: carbon-relay: 1s, normally up, want up; run: log: (pid 59) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: down: collectd: 1s, normally up, want up
Oct 11 03:53:53 ubuntu graphite[16428]: run: cron: (pid 58) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: down: go-carbon: 1s, normally up, want up
Oct 11 03:53:53 ubuntu graphite[16428]: run: graphite: (pid 70) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: run: nginx: (pid 63) 5s
Oct 11 03:53:53 ubuntu graphite[16428]: down: redis: 1s, normally up, want up
Oct 11 03:53:53 ubuntu graphite[16428]: run: statsd: (pid 71) 5s; run: log: (pid 67) 5s

Use the Docker CLI to list the running containers.

$ docker ps
CONTAINER ID        IMAGE                         COMMAND             CREATED              STATUS              PORTS                                                                                                                                                                       NAMES
e5647ba93e4d        graphiteapp/graphite-statsd   "/entrypoint"       About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 0.0.0.0:2003-2004->2003-2004/tcp, 2013-2014/tcp, 8080/tcp, 0.0.0.0:2023-2024->2023-2024/tcp, 0.0.0.0:8126->8126/tcp, 8125/tcp, 0.0.0.0:8125->8125/udp   graphite

If the server has been rebooted, perform a system reboot to ensure that the container has started.

sudo reboot

We can confirm that the container is started with a different ID:

$ docker ps
CONTAINER ID        IMAGE                         COMMAND             CREATED              STATUS              PORTS                                                                                                                                                                       NAMES
11e596067be9        graphiteapp/graphite-statsd   "/entrypoint"       About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 0.0.0.0:2003-2004->2003-2004/tcp, 2013-2014/tcp, 8080/tcp, 0.0.0.0:2023-2024->2023-2024/tcp, 0.0.0.0:8126->8126/tcp, 8125/tcp, 0.0.0.0:8125->8125/udp   graphite

read through Graphite file Start sending metrics from your application to Graphite.

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose

Sidebar