This article will help you to set up the Grafana monitoring tool. Here Grafana will use the InfluxDB database for storing user credential and login details and Telegraf agent for collecting metrics from each node.
System specification:
OS: ubuntu
hostname: mygrafana1.com
IP: 172.30.32.253
To resolve the domain add the IP address and hostname in /etc/hosts file. Once done you could able to ping the hostname from the terminal.
root@mygrafana:~# cat /etc/hosts 127.0.0.1 localhost 172.30.32.253 mygrafana1.com
Telegraf installation:
Add Telegraf repository for apt-get source. Please note Telegraf and Influxdb is developed by the same organization, so we can use the same repo for both tools.
:~# wget -qO- https://repos.influxdata.com/influxdb.key | apt-key add - OK
:~# source /etc/lsb-release
:~#echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" |sudo tee /etc/apt/sources.list.d/influxdb.list
deb https://repos.influxdata.com/ubuntu bionic stable
Install Telegraf
root@mygrafana:~# apt-get update && apt-get -y install telegraf
Start and enable telegraf.
root@mygrafana:~# systemctl start telegraf root@mygrafana:~# systemctl enable telegraf root@mygrafana:~# systemctl status telegraf ● telegraf.service - The plugin-driven server agent for reporting metrics into InfluxDB Loaded: loaded (/lib/systemd/system/telegraf.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-09-10 06:27:38 UTC; 2min 14s ago Docs: https://github.com/influxdata/telegraf Main PID: 2336 (telegraf)
Influxdb Installation:
root@mygrafana:~# apt-get update && apt-get -y install influxdb
Also, to enable basic authentication, uncomment “auth-enabled” line from the configuration file.
sed -i ‘s/#.*auth-enabled.*=.*/auth-enabled = true/g’ /etc/influxdb/influxdb.conf
Start and enable influxdb
root@mygrafana:~# systemctl start influxdb root@mygrafana:~# systemctl enable influxdb root@mygrafana:~# systemctl status influxdb ● influxdb.service - InfluxDB is an open-source, distributed, time series database Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-09-10 06:33:51 UTC; 32s ago
Once the influxdb is installed we have to create a database and user. For this login to the Influxdb terminal and execute the below queries.
root@mygrafana:~# influx Connected to http://localhost:8086 version 1.7.8 InfluxDB shell version: 1.7.8 > create database telegraf; > create user telegraf with password 'telePASS'
Make sure that the created the database and user exist. For this execute below command in influxdb terminal. Enter the “exit” command to exit influxDB.
Restart influxdb service to confirm that the changes are added.
Grafana Installation:
Add the apt-get repository and install the package.
:~# echo "deb https://packages.grafana.com/oss/deb stable main" | tee /etc/apt/sources.list.d/grafana.list
deb https://packages.grafana.com/oss/deb stable main
:~# curl https://packages.grafana.com/gpg.key | apt-key add -
OK
:~# apt-get update && apt-get -y install grafana
After installation starts and enables the service.
root@mygrafana:~# systemctl daemon-reload root@mygrafana:~# systemctl start grafana-server root@mygrafana:~# systemctl enable grafana-server.service root@mygrafana:~# systemctl status grafana-server ● grafana-server.service - Grafana instance Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled; vendor preset: enabled) Active: active (running) since Tue 2019-09-10 06:57:07 UTC; 6s ago Docs: http://docs.grafana.org
We have completed the installation, next to access the Grafana dashboard access server IP address or hostname on the browser. Make sure that you have added the port 3000 (Grafana) in the Ubuntu firewall.
Enter the default username (admin) and password (admin), then we get an option to change the password. Create a new password to login to the dashboard. From the home dashboard, we can configure a data source. Click on “data source” and search for Influxdb.
Select Influxdb as a data source from the search result and configure it as follows.
Save and test. If everything is correct you will get a “Data source working” message.
Next, we have to configure a Dashboard, The dashboard contains all metrics which we can monitor. The dashboard can be added in two ways. One is creating a JSON file and another is by adding Grafana dashboard template ID. Here I am using the template ID method to create a dashboard.
Click on “+” on the left side panel and select import, paste dashboard ID in the first column. Here I am using “Telegraf – System metrics” https://grafana.com/grafana/dashboards/5955 for creating my dashboard and the ID is 5955.
Once you entered the ID it is automatically redirected to the dashboard setup page.
I renamed the page as “Server Status Page” and selected influxdb. Click the “Import” button to continue.
On the next screen, our beautiful dashboard is loading with system metrics like (CPU, Memory, Disk usage, etc)