Prometheus-Grafana monitoring MySQLD && Linux server demo version

Table of contents

The first is to download Prometheus

download and install

Configure Prometheus

View monitoring data

monitor mysql demo

Deploy the mysqld_exporter component

Configure Prometheus to obtain monitoring data

--------------------------------------

Install and use Grafana

Start Grafana

--------------------------------------

Configure data source

Grafana displays MySQL monitoring data

Monitoring cloud server demo

Deploy node_exporter

Configure Prometheus to obtain monitoring data

Then start Grafana as above

Configure data sources (these two data sources are the same, because they are all monitored by local promethus)

Grafana displays Linux monitoring data


The first is to download Prometheus

download and install

First, you need to download and install Prometheus. You can download the latest version of the binaries from Prometheus' official website ( Prometheus - Monitoring system & time series database ). After downloading, you need to extract Prometheus to your computer.

Configure Prometheus

After unpacking Prometheus, you need to configure Prometheus to monitor your application. In the root directory of Prometheus, you'll find a prometheus.ymlfile called . This file contains configuration information for Prometheus.

You need to edit this file and add the targets you want to monitor. In this file, you need to define one or more job. Each jobrepresents a target you want to monitor. For each job, you need to specify a target, which represents the address and port number of the application you want to monitor.

For example, assuming you want to monitor an myappapplication called , running on a port localhoston 8080, your prometheus.ymlfile should look like this:

global:
  scrape_interval: 15s
scrape_configs:
  - job_name: 'myapp'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:8080']

In this configuration, we define a target myappcalled job, which will monitor localhost:8080this target every 5 seconds.

Set the sampling time and evaluation time through configure scrape_intervaland to control the accuracy and latency of the indicator.evaluation_interval

View monitoring data

PS: You need to run node_exporter and mysqld_exporter first, and then run prometheus to make the state corresponding to UP

Once Prometheus starts to monitor your application, it will collect various indicator data, and these data (after startup, you can enter in the browser, http://localhost:9090/visit the UI interface of Prometheus, where you can see the data that can already be collected index.)

At this time, if an error is reported here: get context deadline exceeded, it means that this port is not open. I just opened it on Alibaba Cloud.

Click the link inside, if there is data similar to the following, it means that the deployment of node_exporter is complete.

monitor mysql demo

Deploy the mysqld_exporter component

First find the corresponding mysqld_exporter version in Download | Prometheus .

Transfer mysqld_exporter to the MySQL machine to be monitored and decompress it:

sudo tar zxvf mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /opt

create soft link

sudo ln -s /opt/mysqld_exporter-0.14.0.linux-amd64/ /opt/mysqld_exporter

Create a monitoring user on MySQL

create user 'exporter'@'localhost' IDENTIFIED BY '112233lml!';

mysql> set global read_only=0; 
Query OK, 0 rows affected (0.00 sec) 
mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)
mysql> show variables like '%read_only%'; 
+------------------+-------+ 
| Variable_name  | Value | 
+------------------+-------+
| innodb_read_only | OFF  | 
| read_only    | OFF  | 
| tx_read_only   | OFF  | 
+------------------+-------+
3 rows in set (0.00 sec) 

Password changed successfully, exit skip-grant-tables mode

leenhem@DESKTOP-7SREO20:~$ sudo /etc/init.d/mysql start
 * Starting MySQL database server mysqld            
No directory, logging in with HOME=/            [ OK ]

(Original link: ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot exe_sql error [1290] [hy000]: the mysql server is running_leenhem's blog-CSDN blog )

Create a new configuration file:

sudo vim /opt/mysqld_exporter/mysqld_exporter.cnf

Configure MySQL to monitor user information:

[client] user=exporter password=112233lml!

start mysqld_exporter

sudo nohup /opt/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter/mysqld_exporter.cnf &

show:

http://yourip:9104/metrics

MySQL monitoring data can be obtained, as shown in the figure below (partial data):

Configure Prometheus to obtain monitoring data

We have already configured this

restart prometheus

--------------------------------------

Install and use Grafana

First, you need to download the latest version of the binaries from Grafana's official website ( Download Grafana | Grafana Labs ). After downloading, you need to extract Grafana to your computer. (I am under windows)

Start Grafana

After unpacking Grafana, you need to start Grafana (grafana-server).

This will start Grafana running on the default port 3000. http://localhost:3000You can access Grafana's web interface by navigating in your browser .

(

Default port: 3000

Address: http://ip:3000

Initial administrator account: admin, password: admin

)

--------------------------------------

Configure data source

PS: This is to check whether the installed mysqld_exporter (9104) and node_exporter (9100) are started successfully under linux

Grafana displays MySQL monitoring data

Enter 7362 to import other people's ready-made dashboards

Select the Prometheus data source created before in the prometheus option, click "Import", and it will automatically jump to the following interface:

Monitoring cloud server demo

Deploy node_exporter

1. Download the node_exporter installation package from the official website. The official website download address is as follows: Download | Prometheus

Pass node_exporter to the MySQL machine to be monitored and decompress it:

tar -zxvf node_exporter-1.5.0.linux-amd64.tar.gz -C /opt/

Create a soft link:

sudo ln -s /opt/node_exporter-1.5.0.linux-amd64/ /opt/node_exporter

start up

sudo nohup /opt/node_exporter/node_exporter & (you can run it after downloading, before running Prometheus)

Check

restart prometheus

Then enter in the browser: your ip:9100/metrics (your ip and port) If there is data similar to the following, it means that the deployment of node_exporter is complete.

Configure Prometheus to obtain monitoring data

This is also configured from the beginning

Then start Grafana as above

Configure the data source (these two data sources are the same, because they are all monitored by the local promethus) (so if the configuration above is configured, there is no need to configure it here)

Grafana displays Linux monitoring data

import import 11074

Guess you like

Origin blog.csdn.net/weixin_62700590/article/details/130111223