Installing and configuring Grafana on Ubuntu

Graphite is a scalable metric graphing solution. It’s a popular choice in the enterprise for collecting metrics from multiple sources and producing readable graphs. However, Graphite’s graphing interface isn’t all that user friendly and it’s difficult to showcase the collected metrics. This is where Grafana shines. Grafana is a web front-end for Graphite or InfluxDB. Although they have their own graphing solutions, Grafana is far more powerful and much easier to use. I’ll guide you through installing and configuring Graphite and Grafana on Ubuntu 14.04.


  • Ubuntu 14.04 (for the purpose of this guide)


Run the following command to perform all updates and upgrades to Ubuntu.

sudo apt-get update && sudo apt-get upgrade

Install Apache, Python Tools, and Graphite

The following command will install Graphite as well as the prerequisites.

Note: During the installation of graphite-carbon, you will be asked if you want to remove the whisper database files should you ever uninstall Graphite. Answer No to this prompt. You can always remove the files later (which are located in /var/lib/graphite/whisper).

sudo apt-get install build-essential graphite-web graphite-carbon python-dev apache2 libapache2-mod-wsgi libpq-dev python-psycopg2

Configure Carbon

  1. Edit the Carbon configuration file.
    sudo nano /etc/default/graphite-carbon
  2. Make the following change.
  3. Start the service.
    sudo service carbon-cache start

Install and configure PostgreSQL

By default Graphite will use SQLite. PostgreSQL is much more robust.

  1. Install PostgreSQL.
    sudo apt-get install postgresql
  2. Change to postgres user.
    sudo su postgres
  3. Create a database user. You will be prompted to supply a password. Remember this password as you’ll need it when configuring Graphite.
    createuser graphite --pwprompt
  4. Create the databases for Graphite and Grafana.
    createdb -O graphite graphite
    createdb -O graphite grafana
  5. Then switch back to your user account. For example:
    su - youruseraccountname

Configure Graphite

There are a few configuration changes that need to be made to Graphite.

  1. Update the database settings.
    sudo nano /etc/graphite/
  2. Update the database connection settings to use the PostgreSQL database. Be sure to use the password your specified for the graphite user created in PostgreSQL. For example:
    'default': {
    'NAME': 'graphite',
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'USER': 'graphite',
    'PASSWORD': 'graphite',
    'HOST': '',
    'PORT': ''
  3. Within the same file, update the time zone. Uncomment the TIME_ZONE line and add the correct time zone which matches the server’s time zone. For example:
    TIME_ZONE = 'America/Edmonton'
  4. Within the same file, update the secret key to something long and complicated. Uncomment the SECRET_KEY line and add a random string of letters and numbers. For example:
    SECRET_KEY = 'WH@T3v3RuW@nTG03$h3Re'
  5. Initialize the database. You will be prompted to create a superuser account which will be used to access Graphite’s web interface. Leave the username as root and enter a password.
    sudo graphite-manage syncdb

Configure Apache for Graphite

Apache is required for Graphite.

  1. Copy Graphite’s Apache config template to Apache’s sites-available directory.
    sudo cp /usr/share/graphite-web/apache2-graphite.conf /etc/apache2/sites-available
  2. Change Graphite’s port from 80 to 8080 (port 80 will be used by Grafana).
    sudo nano /etc/apache2/sites-available/apache2-graphite.conf

    Change the following line from port 80 to 8080:

    <VirtualHost *:8080>
  3. Update which ports Apache is listening for.
    sudo nano /etc/apache2/ports.conf

    Add port 8080. For example:

    Listen 80
    Listen 8080
  4. Disable Apache’s default site to avoid any conflicts.
    sudo a2dissite 000-default
  5. Enable Graphite’s virtual site.
    sudo a2ensite apache2-graphite
  6. Reload Apache to apply the changes.
    sudo service apache2 reload
  7. You should now be able to browse to Graphite’s web interface, http://servername:8080.

Install and configure Grafana

The following will outline how to install Grafana on Ubuntu.

  1. Run the following commands to add Grafana’s repository to the sources.list.
    sudo add-apt-repository "deb stable main"
    wget -q -O - | sudo apt-key add -
  2. Install Grafana.
    sudo apt-get update && sudo apt-get install grafana
  3. Edit Grafana’s configuraiton file.
    sudo nano /etc/grafana/grafana.ini

    Update the database connection values to use PostgreSQL. For example:

    type = postgres
    host =
    name = grafana
    user = graphite
    password = graphite

    Update the server configuration. For example:

    protocol = http
    http_addr =
    http_port = 3000
    domain =
    enforce_domain = true
    root_url = %(protocol)s://%(domain)s/

    Update the security information. For example:

    # default admin user, created on startup
    admin_user = admin # default admin password, can be changed before first start of grafana, or in profile settings
    admin_password = admin # used for signing
    secret_key = SW2YcwsfssfsDSFDS8979869t

    Enable anonymous viewing.

    # enable anonymous access
    enabled = true
  4. Enable Apache’s proxy modules for reverse proxying. This will allow Apache to listen to port 80 and proxy the requests to Grafana’s webserver on port 3000.
    sudo a2enmod proxy proxy_http xml2enc
  5. Create an Apache configuration file for Grafana.
    sudo nano /etc/apache2/sites-available/apache2-grafana.conf

    Add the following to the file (replace “” with your domain):

    ProxyPreserveHost On
    ProxyPass /
    ProxyPassReverse /
  6. Enable the Grafana website in Apache.
    sudo a2ensite apache2-grafana
  7. Configure Grafana to run after boot.
    sudo update-rc.d grafana-server defaults 95 10
  8. Start the Grafana server.
    sudo service grafana-server start
  9. Restart Apache.
    sudo service apache2 restart
  10. Browse to http://servername.

Add Graphite as a data source within Grafana.

Adding a data source to Grafana is fairly straight forward.

  1. Log in into Grafana using the admin credentials you specified in grafana.ini above.
  2. Click on Data Sources and select Add new.
  3. Provide the datasource the name of “graphite”.
  4. Select Graphite as the type.
  5. Enter the URL http://servername:8080.
  6. Accept all other defaults and click Save to create the new Data Source.

Sending data to Graphite

There are many ways to send data to Graphite. Many monitoring solutions will have the option to send metrics to Graphite. If you use VMware, you can send vCenter statistics to Graphite/Grafana with using a PowerShell script.

Create your first dashboard and graph

Once you have metrics in Graphite, you can begin graphing. Below is a video from the Grafana YouTube channel which includes steps for creating a dashboard and a graph.

One comment

Leave a Reply