Monitor your production systems and application analytics using Grafana and Graphite. This article will help you setup these tools on Ubuntu 14.04 on a Nginx webserver with PostgreSQL as backend.
Before starting following this setup, please go through my previous post on Deploy Graphite and Nginx on an Ubuntu 14.04 server
What is what
What is Grafana?
Grafana is a tool for visualising time-series data for various application analytics. It is a great tool when used in combination with Graphite. It gives us flexibility of creating dashboards and share them with teams. Grafana Official
Installing Graphite
To install Graphite please follow this tutorial on Deploy Graphite and Nginx on an Ubuntu 14.04 server.
Installing Grafana
Install Ubuntu Packages
Executing following commands will install Grafana on your machine
echo 'deb https://packagecloud.io/grafana/stable/debian/ wheezy main' | sudo tee -a /etc/apt/sources.list
curl https://packagecloud.io/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafana
Create a database for Grafana
Just as we created the database for Graphite on PostgreSQL, we will create a database for Grafana as well. Create a database grafana and give user graphite (the user having access to Graphite database) ownership of it.
$ CREATE DATABASE grafana WITH OWNER graphite;
Configure Grafana
Edit the Grafana configuration file
sudo vim /etc/grafana/grafana.ini
The settings should be something like this
[database]
type = postgres
host = 127.0.0.1:5432
name = grafana
user = graphite
password = mypassword
[server]
protocol = http
http_addr = 127.0.0.1
http_port = 3000
domain = grafana.yourservername.com
enforce_domain = true
root_url = %(protocol)s://%(domain)s/
[security]
admin_user = admin
admin_password = your_secure_password
secret_key = your_random_secret_salt
Once your configuration is done, you can start Grafana Server by running
sudo service grafana-server start
The log files are located at /var/log/grafana/grafana.log
If everything goes well the log file should have content
$ tail /var/log/grafana/grafana.log
[0]: default.paths.data=/var/lib/grafana
[1]: default.paths.logs=/var/log/grafana
Paths:
home: /usr/share/grafana
data: /var/lib/grafana
logs: /var/log/grafana
2015/12/16 06:37:15 [I] Database: postgres
2015/12/16 06:37:15 [I] Migrator: Starting DB migration
2015/12/16 06:37:15 [I] Listen: http://127.0.0.1:3000
Setup Nginx for Graphite
Let us first create all files and links
sudo touch /etc/nginx/sites-enabled/grafana
sudo ln -s /etc/nginx/sites-enabled/grafana /etc/nginx/sites-available/grafana
# Log files
sudo touch /var/log/nginx/grafana.access.log
sudo chmod 666 /var/log/nginx/grafana.access.log
sudo touch /var/log/nginx/grafana.error.log
sudo chmod 666 /var/log/nginx/grafana.error.log
Now we are ready for configuring Nginx server for Grafana
Open file /etc/nginx/sites-enabled/grafana and put following content in it
sudo vim /etc/nginx/sites-enabled/grafana
Nginx configuration
server {
server_name grafana.yourservername.com;
listen 80;
rewrite ^(.*) https://$host$1 permanent;
}
server {
server_name grafana.yourservername.com;
listen 443 ssl spdy;
access_log /var/log/nginx/grafana.access.log;
error_log /var/log/nginx/grafana.error.log;
location = /robots.txt {
echo "User-agent: *\nDisallow: /\n";
}
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
}
}
Now you can view a working Grafana on your server. Just hit http://grafana.yourservername.com from your favourite browser.
See it working
Once you open the Grafana page, you will see a page something like this.
Log in to the system with default credentials
- username: admin
- password: admin
Once you are logged in, you should see a screen like this.
Before you see any analytics information here, you should add your data source. The data source you will add will be Graphite that was setup earlier.
Goto Data Source -> Add New
Make following changes:
- Name: graphite
- URL: graphite.yourservername.com
You should test your connection before adding any dashboard.
Once the connection is successful, now we are ready to add our first dashboard. Go to home page and goto New Dashboard -> New
Once that is done, you can add panels to it. To add graphs in panels click on Green Button -> Add Panel -> Graph. At the botton you will see metrics in which select test and count. Then you will see screen something like this.
More Information
Please follow the below links in order to know more about Grafana and its amazing customizations.