One of Prometheus implements graphical monitoring

1:prometheus

1. Download:

  1. Go to the official website to download the prometheus file to your computer—— Go to the official website of Prometheus to download the address
  2. Copy the download address of prometheus and directly download it to the server using the relevant commands.

Prometheus source package download address: This link is version 2.46 and only applies to Linux systems

https://github.com/prometheus/prometheus/releases/download/v2.46.0/prometheus-2.46.0.linux-amd64.tar.gz

2. Installation:

Ready to unzip

tar -zxvf /path/to/prometheus-2.46.0.linux-amd64.tar.gz -C /path/install/prometheus
#说明:从存放压缩包的环境解压到指定的安装目录

3. Start:

1: Add systemctl to one of the startup methods

1: Join the system management. Generally, add it to the user directory.
System directory: /usr/lib/systemd/system
User directory: /etc/systemd/system

Reference prometheus.service

[Unit]
Description=https://prometheus.io
# 这里是对服务的描述,通常简要说明服务的功能或用途。

[Service]
Restart=on-failure
# 这里指定了服务的行为。"Restart=on-failure"表示如果服务出现失败,则会自动重新启动。

ExecStart=/home/jiang/prometheus/prometheus/prometheus --config.file=/home/jiang/prometheus/prometheus/prometheus.yml
# 这是服务启动时要执行的命令。它指定了启动Prometheus的可执行文件路径,并通过--config.file选项指定了使用的配置文件路径。

[Install]
WantedBy=multi-user.target
# 这里定义了服务的安装位置和启动级别。"WantedBy=multi-user.target"表示在多用户环境下启用服务。

vim /etc/systemd/system/prometheus.service
# 内容为上文的参考内容
systemctl daemon-reload
# 刷新内容
systemctl start prometheus.service
# 启动服务
systemctl status prometheus.service
# 查看状态

2: Startup method two—direct startup

1: Enter the installation directory
2:

./prometheus [--config.file=/config_path/to/*.yml]
# 说明[]里的可选

3: Startup method three----running in the background

nohub /path/to//prometheus [--config.file=/config_path/to/*.yml] &
# 说明[]里的可选

4: Explanation of the default configuration file prometheus.yml

# 全局配置
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# 警报管理器的相关的配置
 alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093


# 配置相关的报警规则,目录可以自己指定
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
  # - /usr/lib/prometheus/rules/*.rules


# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
# 添加配置的节点
scrape_configs:
  # 作业名称作为标签“job=<job_name>”添加到从此配置抓取的任何时间序列中。
  - job_name: "prometheus"

    # metrics_path 默认为 '/metrics'
    # scheme 默认为 'http'.

    static_configs:
    # 如果需要监控的不止这一个,且远程服务器也安装了普罗米修斯,且端口有开放,则可以继续在- targets其中添加,下同. 比如服务器的地址为10.10.101.200
      - targets: ["localhost:9090","10.10.101.200:9090"]
  
  # 以下的内容是自己添加的,这里有两个服务,一个是关于服务器基本信息的,一个是关于数据库的基本信息
  - job_name: "node_exporter"
    static_configs:
      - targets: ["localhost:9100"]
  

  - job_name: "mysqld_exporter"
    static_configs:
      - targets: ["localhost:9105"]

2: Use Node Exporter to collect host operating data

1: Download and install

Official website download,

2: Start

1: One of the startup methods—join system management

cat >> /etc/systemd/system/node_exporter.service <<EOF
[Unit]
Description=node exporter service
Documentation=https://prometheus.io
After=network.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/home/jiang/prometheus/node_exporter/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
# 刷新内容
systemctl start prometheus.service
# 启动服务
systemctl status prometheus.service
# 查看状态

2: Startup method two—direct startup

1: Enter the installation directory
2:

./node_exporter

3: Startup method three----running in the background

nohub /path/to/node_exporter &
# 说明[]里的可选

3: Test

If it is a virtual machine, please turn off the firewall or add corresponding rules. After
successful startup, it should look like the picture.
success interface

4: Edit prometheus.yml

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]
# 添加这个
  - job_name: "node"

    static_configs:
      - targets: ["localhost:9100"]

Restart prometheus

systemctl restart prometheus

5: Check whether the service is added successfully

1: Enter the prometheus interface

3: Monitoring data visualization----Use Grafana to create a visual Dashboard

1: Download and install

This is the official guide , which contains all installation methods.

The following is the installation method for Red Hat, CentOS, and RHEL versions of the system

sudo yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-10.0.3-1.x86_64.rpm

2: Start Grafana

systemctl daemon-reload
systemctl start grafana-server.service
systemctl enable grafana-server.service

3: Check whether the port is listening

netstat -tulnp | grep :3000
tcp6 0 0 :::3000 :::* LISTEN 24024/grafana-serve

4: Visit Grafana

http://ip:3000
admin/admin
Insert image description here
After successful login
Insert image description here

5: Configure data source

Insert image description here
Insert image description here

Insert image description here

Insert image description here
Insert image description here

6: Install the corresponding Dashboard

After adding the data source in the previous step, the visualization has been completed. Graphics can be generated by querying the time series, as shown below. However, as an
Insert image description here
open source software, the Grafana community encourages users to share Dashboard . You can find a large number of them through the https://grafana.com/dashboards website. Ready-to-use Dashboard:

How to join Dashboard?
Insert image description here

Insert image description here
The effect after adding.
Insert image description here

998: Problems encountered during installation (updated from time to time)

1: Prometheus data is not displayed due to out-of-sync time.

Problem: As shown in the figure
Insert image description here
Solution:

yum -y install ntp

systemctl enable ntpd

ntpdate time1.aliyun.com

Insert image description here

999: Put it last

1: Source of information:

1: Prometheus official website---- https://prometheus.io/
The latest, most complete and best, but not in Chinese
2: Prometheus Chinese documentation----- https://www.prometheus .wang/
I personally think it is very useful, but it has not been updated for a long time, and some of the things in it are out of date.

3: Resource sharing

Insert image description here
Well, there is no internet now. I will upload it to the network disk and then share the network disk link.

Guess you like

Origin blog.csdn.net/m0_51828898/article/details/132210346