Technology Sharing

Prometheus Review (2) - The detailed process of how to use Grafana to connect to the Prometheus data source is clear and easy to understand.

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina


Introduction to Grafana

Grafana is a tool for viewing and analyzing data, and is particularly good at monitoring and visualizing time series data.

What is Grafana

Visualization Tools: Grafana can turn data into charts, making it easier for you to understand and analyze data.
Open Source Software: Anyone can use and modify it for free.

What can Grafana do?

Connect different data sources: It can obtain data from a variety of data sources, such as Prometheus, Elasticsearch, MySQL, etc.
Create a dashboard: You can create dashboards containing various charts to monitor and present data.
To set an alarm: When the data meets a certain condition, Grafana can send a notification to remind you.
teamwork: Different users can use and manage Grafana together, and each has different access permissions.

When will we use Grafana?

Server Monitoring: View server performance, such as CPU usage, memory usage, etc.
Application Monitoring: Monitor application health and performance.
Business data analysis: Analyze business indicators such as sales data, user activity, etc.
IoT Data Visualization: View data from sensors in real time.

Prometheus has graphical display, why do we still need Grafana?

Although Prometheus has built-in basic graphical display functions, Grafana provides a more powerful, flexible and user-friendly visualization and monitoring solution. For scenarios that require complex charts, integration of multiple data sources, detailed alerts and team collaboration, Grafana is a more suitable choice.

environment

virtual machine

IpCPU namecpuMemoryharddisk
192.168.10.14prometheus-server2c2G100G
192.168.10.15prometheus-agent2c2G100G
192.168.10.16grafana2c2G100G

Version centos7.9
Initialization completed (firewall, sandbox, hostname)
prometheus is installed
Please refer to the previous article for prometheus installation. I will not repeat it here.
Link:Prometheus Review (1) – Installing Prometheus monitoring in binary mode on Linux

Steps

1. Grafana Installation

This article will use binary installation, and containerized installation will be shown in subsequent articles

Get the binary package

wget https://dl.grafana.com/oss/release/grafana-10.0.1.linux-amd64.tar.gz
  • 1

Unpack and view

tar xf grafana-10.0.1.linux-amd64.tar.gz
ls
  • 1
  • 2

insert image description here

Move to /usr/local/ for easy management

mv grafana-10.0.1 /usr/local/grafana
cd /usr/local/grafana/
ls
  • 1
  • 2
  • 3

There are the following files
insert image description here

For easy management, register it as a system service

cat > /usr/lib/systemd/system/grafana.service << EOF
[Service]
ExecStart=/usr/local/grafana/bin/grafana-server --config=/usr/local/grafana/conf/defaults.ini --homepath=/usr/local/grafana
 
[Install]
WantedBy=multi-user.target
 
[Unit]
Description=grafana
After=network.target
EOF
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Reload/Auto-start/Check status/Start

systemctl daemon-reload
systemctl enable grafana
 systemctl start grafana
 systemctl status grafana
  • 1
  • 2
  • 3
  • 4

insert image description here

Grafana Access
Host browser access
Local ip:3000
here it is

192.168.10.16:3000
  • 1

You will see the following interface
insert image description here
enter
Default account: admin
Default password: admin
Just log in
insert image description here
You will be asked to reset your password later. If you don't want to reset it, just click skip.
insert image description here
Next you will enter the main interface
insert image description here

2. Adding Prometheus as the Grafana data source

Click the three dashes in the upper left corner
Then click Data sources in the interface that appears.
insert image description here
Then click Add data source in the interface that appears.
A
Click prometheus again and select prometheus as the data source
insert image description here
Enter after the Prometheus server URL
Prometheus access address, that is

http://192.168.10.14:9090
  • 1

insert image description here

Then scroll to the end and click save&test
insert image description here
A check mark is displayed indicating that the prometheus data source is successful
insert image description here

3. Grafana adds data dashboard

Then click Dashboards
insert image description here
Click new, then select import
insert image description here
You can see that there are two ways to add a dashboard
One is json format
One is ID
Here we use ID
This is a dashboard about liunx host

12633
  • 1

At the end there will be a tutorial on how to find the right dashboard according to your needs
insert image description here
insert image description here

Click Import
insert image description here
This is the monitoring interface.
insert image description here
insert image description here

Supplement: How to find the dashboard

Browser Search

grafana.com
  • 1

insert image description here
You need to register an account here first
Visit after registration

https://grafana.com/grafana/dashboards/
  • 1

You can
Then you can search the dashboard as needed
insert image description here
For example, the dashboard just now
Search for liunx host
You can see that the first one is the dashboard template we use
click it
insert image description here
There are two usage methods provided in this interface
Download the json file or copy the ID
You can also see what its id is
insert image description here