How Install Graphite and Graphite-Web on Linux with docker and systemd

Graphite is a free open-source software tool that monitors and graphs numeric time-series data such as the performance of computer systems. Graphite monitoring provides operations teams with visibility on varying levels of granularity concerning the behavior and mannerisms of the systems and applications. This leads to error detection, resolution, and continuous improvement.

Graphite stores numeric time-series data (metric, value, epoch timestamp) and renders graphs of this data on demand. A time-series is a sequence of observations taken sequentially in time. Time series analysis reveals trends and patterns associated with external factors and anomalies. With adequate graphing teams and enough time series data, it’s even possible to intuitively forecast future events.

As Graphites design is orientated towards modularity and doing one thing very well, there is no direct data collection support. Carbon, one of the three Graphite components, listens passively for data. Solutions such as StatsD and CollectD are used to collect and parse data upstream to Graphite as different protocols. 

The main graphite components are:

  1. carbon – a Twisted daemon that listens for time-series data
  2. whisper – a simple database library for storing time-series data (similar in design to RRD)
  3. graphite webapp – A Django webapp that renders graphs on-demand using Cairo

# Table of content

  1. Ensure docker is locally installed
  2. Running Graphite
  3. Accessing Graphite web interface
  4. Managing Graphite container with systemd
  5. Starting and enabling graphite-docker service

# 1. Ensure that docker installed

Since we are using docker to run graphite, ensure it is installed before proceeding. If you don’t have docker installed, check these guides:

Check installed docker version using this command:

$ docker version
Client: Docker Engine - Community
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:45:33 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.12
  Git commit:       459d0df
  Built:            Mon Dec 13 11:43:42 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

# 2. Running Graphite

The simplest way of running graphite is using its docker components. This will save you the time of installing each component and setting its dependencies. The docker project work can be found in this github repo.

The docker image includes the following components:

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

The following ports are exposed from the container. We will map them locally later:

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

Create data directories to persist container data. They’ll be mapped to container volumes when starting the container.

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

Now run this command in your terminal:

docker run --rm \
    --name graphite \
    -p 8090: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 /var/log/graphite:/var/log \
    -e GRAPHITE_TIME_ZONE='Africa/Nairobi' \
    graphiteapp/graphite-statsd:1.1.8-5-pypy

If you are running the above command for the first time, it will download the latest Graphite and Statsd container images.

# 3. Access Graphite Web interface

Since we mapped port 80 to 8090 in the above docker run command, we will use that to access the web interface. Use your Server IP address on port 8090 to access Graphite web interface.

Citizix - graphite web

Citizix – graphite web

The default logins creds are:

Username: root
Password: root

# 4. Managing Graphite Container with systemd

To manage the container easily and to ensure that it starts on boot, we can use systemd. Systemd is a Linux service manager that comes with most modern linux distros. Use this command to create a systemd service file for our Graphite

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

[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:<meta charset="utf-8">1.1.8-5-pypy
ExecStart=/usr/bin/docker run --rm \
            --name graphite \
            -p 8090: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 /var/log/graphite:/var/log \
            -e GRAPHITE_TIME_ZONE='Africa/Johannesburg' \
            graphiteapp/graphite-statsd:1.1.8-5-pypy

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

[Install]
WantedBy=multi-user.target
EOF

Reload Systemd to get new units.

sudo systemctl daemon-reload

Confirm graphite-docker unit file is created.

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

1 unit files listed.

# 5. Starting and enabling

graphite-docker service {.wp-block-heading}

We have to start the service. Use this command:

sudo systemctl start <meta charset="utf-8">graphite-docker

Confirm that it is working as expected:

<meta charset="utf-8">$ sudo systemctl status graphite-docker
● graphite-docker.service - Graphite Docker Container
     Loaded: loaded (/etc/systemd/system/graphite-docker.service; disabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-01-20 14:01:37 UTC; 1min 30s ago
       Docs: https://github.com/graphite-project/docker-graphite-statsd
    Process: 153356 ExecStartPre=/usr/bin/docker kill graphite (code=exited, status=1/FAILURE)
    Process: 153362 ExecStartPre=/usr/bin/docker rm graphite (code=exited, status=1/FAILURE)
    Process: 153368 ExecStartPre=/usr/bin/docker pull graphiteapp/graphite-statsd:1.1.8-5-pypy (code=exited, status=0/SUCCESS)
   Main PID: 153380 (docker)
      Tasks: 7 (limit: 4624)
     Memory: 19.2M
     CGroup: /system.slice/graphite-docker.service
             └─153380 /usr/bin/docker run --rm --name graphite -p 8090:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 -v /data/graphite/data:/opt/gra>

Jan 20 14:02:19 ubuntusrv.citizix.com graphite[153380]: 20/01/2022 14:02:19 :: [listener] MetricLineReceiver connection with 127.0.0.1:37382 established

The above output shows that the service is running. To enable the service on boot use this command:

sudo systemctl enable graphite-docker

That is it! We have managed to get graphite up and running in this guide.

Last updated on Mar 20, 2024 17:19 +0300
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy