Using a Different System?
-
How to Install and Configure Graphite on CentOS 7
Graphite is a free and open source tool that can be used to track and graph the performance of computer systems. Graphite is an application that can be used to gather information from your system and display it through its web interface.
In this tutorial, I will explain how to install and configure Graphite on Ubuntu 16.04.
Prerequisites
- A newly deployed Vultr Ubuntu 16.04 server instance.
- A non-root user with sudo privileges setup on your server.
- A static IP address 192.168.0.227 configured on your system.
Step 1: Update the system
First, update your system to the latest stable version by running the following command:
sudo apt-get update -y
sudo apt-get upgrade -y
Once your system is updated, restart your system to apply these changes:
sudo reboot
Step 2: Install Graphite
Graphite is made up of several components including, the graphite web application, carbon storage backend, and the database library, whisper. Each of these components are available in Ubuntu default repository. You can install these by just running the following command:
sudo apt-get install graphite-web graphite-carbon -y
Once the installation is complete, you can proceed to the next step.
Step 3: Install and configure PostgreSQL
The Graphite web application is a Django Python application that needs PostgreSQL to store its data. You can install PostgreSQL and the helper packages by running the following command:
sudo apt-get install postgresql libpq-dev python-psycopg2 -y
After installing PostgreSQL, you will need to create a PostgreSQL user and database for Graphite to use.
First, login to PostgreSQL shell with the following command:
sudo -u postgres psql
Next, create a graphite user and secure it with a password:
postgres=# CREATE USER graphite WITH PASSWORD 'password';
Next, create a graphite database and give ownership to the graphite user:
postgres=# CREATE DATABASE graphite WITH OWNER graphite;
Finally, exit from the PostgreSQL shell:
postgres=# /q
Step 4: Configure Graphite
Once the database is setup properly, you will need to configure the Graphite web application. You can do this by editing the local_settings.py
file:
sudo nano /etc/graphite/local_settings.py
Edit the file as shown below:
SECRET_KEY = 'your-secret-key'
TIME_ZONE = 'America/Los_Angeles'
USE_REMOTE_USER_AUTHENTICATION = True
DATABASES = {
'default': {
'NAME': 'graphite',
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'graphite',
'PASSWORD': 'password',
'HOST': '127.0.0.1',
'PORT': ''
}
}
Save and close the file, when you are finished.
Next, run the following command to sync the database to create the correct structure:
sudo graphite-manage migrate auth
sudo graphite-manage syncdb
You will be asked to create a superuser account for the database as shown in the following output:
Operations to perform:
Synchronize unmigrated apps: account, cli, render, whitelist, metrics, url_shortener, dashboard, composer, events, browser
Apply all migrations: admin, contenttypes, tagging, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
No migrations to apply.
You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use 'root'):
Email address: you@example.com
Password:
Password (again):
Superuser created successfully.
Step 5: Configure Carbon
Now, you will need to configure Carbon, the Graphite storage backend by editing the service configuration file, graphite-carbon
.
sudo nano /etc/default/graphite-carbon
Change the file to enable carbon-cache
to start on boot:
CARBON_CACHE_ENABLED=true
Save and close the file, when you are finished.
Next, open the Carbon configuration file:
sudo nano /etc/carbon/carbon.conf
Change the file as shown below to enable log rotation:
ENABLE_LOGROTATION = True
Save the file, then configure storage schemas. To do so, edit the storage schema file to tell Carbon how long to store values and how detailed these values should be there:
sudo nano /etc/carbon/storage-schemas.conf
Add the following section at the end of the file:
[test]
pattern = ^test/.
retentions = 6s:4h,1m:1d
Save and close the file when you are finished.
Next, you will need to define the way you want aggregation to occur in a file called storage-aggregation.conf
. Copy the example configuration file to the Carbon configuration directory:
sudo cp /usr/share/doc/graphite-carbon/examples/storage-aggregation.conf.example /etc/carbon/storage-aggregation.conf
Finally, start Carbon service with the following command:
sudo systemctl start carbon-cache
Step 6: Configure Apache for Graphite
You will also need to install the Apache web server to use the Graphite web interface. You can install Apache with the following command:
sudo apt-get install apache2 libapache2-mod-wsgi -y
Next, copy the graphite example configuration file to Apache with the following command:
sudo cp /usr/share/graphite-web/apache2-graphite.conf /etc/apache2/sites-available/
Once the installation is complete, disable the default virtual host file and enable the graphite virtual host file with the following command:
sudo a2dissite 000-default
sudo a2ensite apache2-graphite
Finally, restart the Apache service to apply these changes:
sudo systemctl restart apache2
Step 7: Access Graphite web interface
Next, You will need to allow port 80
through UFW firewall to access the Graphite web interface. You can do this by running the following commands:
sudo ufw allow 80
It’s time to access Graphite web interface. Open your favorite web browser and type the URL http://192.168.0.227
. Then, provide your login credentials (your root username and password), you will see the Graphite login screen.
Want to contribute?
You could earn up to $300 by adding new articles
Suggest an update
Request an article