---
title: "Grafana, the best visualization tool for monitoring?"
url: "https://vanducng.dev/2019/12/04/Grafana-the-best-visualization-tool-for-monitoring/"
date: "2019-12-04"
categories: ["DevOps"]
tags: ["docker"]
---

# Grafana, the best visualization tool for monitoring?

<p align="center">
	<image src="/media/gifs/grafana-quick-tour.gif" alt="grafana" width="100%" />
</p>

Grafana is an open-source web application specialized in time-series visualization. Hence, it is suitable for the the purpose of monitoring. One of interesting facts is that[ Grafana is a fork from Kibana 3](https://grafana.com/blog/2019/09/03/the-mostly-complete-history-of-grafana-ux/) to enhance the ability of dashboard editing and make it as a clean and elegant time-series visualization tool. To get the sense of Grafana dashboard, surf this link: [https://play.grafana.org](https://play.grafana.org).

> **Info**
>
> If you are looking for kind of visualization tool in business intelligent category, please consider other ones like Superset, Redash, etc.

## Installation
CentOS 7 is a selected as demonstration, should be similar to other Linux distro.

**1. Download and install, find the latest version from here.**

```bash
wget https://dl.grafana.com/oss/release/grafana-6.5.2-1.x86_64.rpm
sudo yum localinstall grafana-6.5.2-1.x86_64.rpm
```

**2. Start the server**

```bash
sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-serve
```

**3. Enable Grafana to start at boot**

```bash
sudo systemctl enable grafana-server.service
```

> **Info**
>
> You should be able to access Grafana UI after step#3, further configurations can be referred in step#4 & step#5 to make it ready for production.


**4. Update /etc/grafana/grafana.ini file**

- Server
```bash
domain = vanducng.dev
root_url = https://grafana.vanducng.dev
```

- SMTP/Email
```bash 
#################################### SMTP / Emailing ##########################
[smtp]
enabled = true
host = mail.vanducng.dev:587
user = alert@vanducng.dev
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = xxxx
#cert_file =
#key_file =
skip_verify = true
from_address = alert@vanducng.dev
from_name = Grafana Alert
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com

[emails]
welcome_email_on_sign_up = true
```

- External storage
```bash 
#################################### External image storage ##########################
[external_image_storage]
# Used for uploading images to public servers so they can be included in slack/email messages.
# you can choose between (s3, webdav, gcs, azure_blob, local)
provider = s3
 
[external_image_storage.s3]
bucket = vanducng-services
region = ap-southeast-1
path = s3://vanducng-services/grafana-images
access_key = xxxxx
secret_key = xxxxx
```

**5. Update /etc/grafana/ldap.toml**

Grafana supports LDAP integration simply by editing this config file.
```bash 
bind_dn = "cn=admin,dc=vanducng,dc=dev"
bind_password = 'xxx'

search_filter = "(uid=%s)"
 
search_base_dns = ["ou=people,dc=vanducng,dc=dev"]
 
group_search_filter = "(&(objectClass=groupOfNames)(memberOf=cn=admin,ou=grafana,ou=groups,dc=vanducng,dc=dev))"
group_search_base_dns = ["ou=grafana,ou=groups,dc=vanducng,dc=dev"]
#group_search_filter_user_attribute = "member=uid"

# Specify names of the ldap attributes your ldap uses
[servers.attributes]
name = "givenName"
surname = "sn"
username = "uid"
member_of = "cn"
email =  "mail"

# Map ldap groups to grafana org roles
[[servers.group_mappings]]
group_dn = "admin"
org_role = "Admin"
grafana_admin = true
```

## Setting Alert
One of great feature on Grafana is ability to set alert to send email or notification.

- **Email**

Setup email channel as following, then limit trigger from particular metric on a dashboard will be sent to list of email.
<p align="center">
		<image src="/media/images/grafana-mail.png" width="60%" "/>
</p>

- **Push Notification**

MSTeam is used for this demonstrattion, from your created group in MSTeam, follow below step to generate Webhook URL.
<p align="center">
		<image src="/media/images/grafana-msteam1.png" width="100%" "/>
</p>

From Grafana, paste the Webhook URL from previous step with bellow settings:
<p align="center">
		<image src="/media/images/grafana-msteam2.png" width="70%" "/>
</p>
