Grafana - Getting started with Installation and Configuration


Grafana is one of the most popular multi-platform, open-source software for monitoring and observability. It allow us to query, visualize, alert on and explore various metrics, logs, and traces from different data sources, no matter where they are stored. With the help of grafana, we can create customized dashboards using several visualization tools like graphs, charts, heatmaps, histograms, geomaps, tables, text panels and many others. Also, we can easily share dashboards with all the stakeholders of a project.

Since, grafana server is a plugin based system, we can use hundreds of both inbuilt and third-party plugins to connect with various data sources as well as, expand the number of options to create visualizations in a dashboard. We can also create custom plugins, if our requirements are not satisfied by any existing plugins. To see a list of plugins, check following url:

https://grafana.com/grafana/plugins/

We can monitor and observe various servers, systems, databases and application services using grafana either in a single dashboard or using multiple dashboards. It can be easily integrated with a number of data sources like Graphite, Prometheus, Influx DB, Elasticsearch, MySQL, PostgresSQL, MongoDB etc. For these various data sources, there are also pre-configured dashboards, which can be instantly used to create dashboards. It can be accessed using following link:

https://grafana.com/grafana/dashboards/

Install Grafana on Amazon Linux 2

Let's update all the packages to their latest available versions and also remove all the obsolete packages:

   
   	sudo yum -y update && sudo yum -y upgrade
   

To install grafana server, we can either use enterprise version or open-source version of the product. Since, enterprise version is available for free and includes all the features of open source version and if needed, also easily upgradable to the enterprise set of features, the recommended version for installation is enterprise edition.

For enabling installation of grafana using yum package manager, we need to add grafana YUM respository to our system's software repository list, so that system knows where to download it and which version to use for downloading. Issue following command to create a repo file:

   
   	sudo vi /etc/yum.repos.d/grafana.repo
   

For Enterprise releases:

This is the recommended version for installing grafana. Paste following content in grafana.repo file:

   
[grafana]
name=grafana
baseurl=https://packages.grafana.com/enterprise/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
   

Now, issue following command to install enterprise edition of grafana server:

   
	sudo yum install grafana-enterprise -y
   

For Open-Source releases:

If we want to specifically install the open-source version of grafana, paste following content in grafana.repo file,

   
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
   

Now, issue following command to install open-source edition of grafana server:

   
	sudo yum install grafana -y
   

Install Grafana on Ubuntu

Let's update all the packages to their latest available versions and also remove all the obsolete packages:

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

For Enterprise releases:

This is the recommended version for installing grafana. Issue following sets of commands to install enterprise edition of grafana:

   
sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
sudo wget -q -O /usr/share/keyrings/grafana.key https://packages.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://packages.grafana.com/enterprise/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update -y
sudo apt-get install grafana-enterprise -y
   

For Open-Source releases:

To install latest open-source version of grafana, issue following command:

   
sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
sudo wget -q -O /usr/share/keyrings/grafana.key https://packages.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update -y
sudo apt-get install grafana -y
   

Now, check the version of grafana server:

   
	grafana-cli -v
   

It should give similar output as shown below:

   
	Grafana CLI version 9.1.0
   

To reload the modification in system configurations, issue following command:

   
   	sudo systemctl daemon-reload
   

To start grafana server:

   
   	sudo systemctl start grafana-server
   

To check the status of grafana server:

   
   	sudo systemctl status grafana-server
   
grafana server status check

To make sure that grafana server starts after each system reboot, issue following command:

   
   	sudo systemctl enable grafana-server
   

By default, grafana is configured with sqlite database and if required, we can also configure grafana with other databases as well. Following is default package details for the grafana installation:

File Directory Location
binary /usr/sbin/grafana-server
configuration file /etc/grafana/grafana.ini
log file /var/log/grafana/grafana.log
sqlite3 database /var/lib/grafana/grafana.db
environment vars /etc/sysconfig/grafana-server

Install Grafana on macOS


We can install grafana on macOS using brew. First, we need to update all the packages in our system.

   
   	brew update && brew upgrade
   

Issue following command to install grafana:

   
   	brew install grafana
   

Start the grafana server using following command:

   
   	brew services start grafana
   

Stop the grafana server using following command:

   
   	brew services stop grafana
   

Install Grafana on Windows


To install grafana on windows, we need to download the installer package. After package is downloaded, open and run the installer. To download latest version, click on the following link:

https://grafana.com/grafana/download?platform=windows

Now that installation is completed, we can run grafana by navigating to following url in the browser:

http://localhost:3000/

For login credentials, default values are:

Username admin
Password admin
grafana server login page

On first successful login, we are required to change the default password for admin user. To create a strong password, it should have following characteristics:

  • At least 1 uppercase letter
  • At least 1 lowercase letter
  • At least 1 number
  • At least 1 special character
  • At least 8 characters long
  • Do not use any well know words, make the password as unique as possible so that dictionary attacks could be prevented
grafana server first time password modification page

We will be redirected to dashboard page after successful password modification:

grafana server dashboard page

Click on panel shown by red-arrow to add data sources for the grafana. We can add multiple data-sources, as we require.

grafana server add data sources page

For our purpose of monitoring NGINX web server in upcoming chapter, we need to add data source for prometheus. Click on Prometheus option:

Replace http://54.70.182.114:9090 with your prometheus server url.

grafana server add data sources - prometheus url

To see a list of data sources, navigate to the following url:

http://localhost:3000/datasources

grafana server list of data sources

Note:

If you are using cloud server, you need to open port 3000 for inbound connections. For security reasons, since this is an internal monitoring tool, we can install it in a private server instance and make it accessible to the internet using proxy web server like NGINX. Also, we can further secure it by making it accessible using VPN connection only.

In our next chapter, we will discuss about monitoring NGINX web server using both Prometheus and Grafana.

Prev Chapter                                                                                          Next Chapter