• 性能测试必备技能:Prometheus监控平台搭建


    01 Prometheus 监控平台部署

    Linux 操作系统监控 + Mysql 监控

    1、平台监控原理:

    环境说明:

    本文档中各组件运行的环境为 Ubuntu(64 位操作系统)

    node_exporter 监控的是 192.168.1.26 机器的操作系统

    mysql_exporter 监控的是 192.168.1.30 上安装的 MySQL 数据库

    Grafana+Prometheus 部署在 192.168.1.33 机器

    部署前的准备:

    关闭所有 Linux 机器的防火墙:systemctl stop firewalld.service

    保证所有 Linux 机器的时间是准确的,执行 date 命令检查;如果不准确,建议使用ntp 同步最新网络时间

    02 部署 Linux 操作系统监控组件

    1、下载监控 Linux 的 exporter
    https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz

    2、将 node_exporter 包上传到需要被监控的 Linux 服务器上任意目录下,执行解压命令

    tar xvf node_exporter-0.18.1.linux-amd64.tar.gz

    图片

    3、进入到解压后的文件夹中,执行启动脚本
    node_exporter-0.18.1.linux-amd64
    nohup ./node_exporter &

    4、查看 nohup 日志,出现如下日志,代表启动成功
    tail -100 nohup.out

    图片

    03 部署prometheus

    1、下载包

    https://github.com/prometheus/prometheus/releases/download/v2.15.2/prometheus-2.15.2.linux-amd64.tar.gz

    2、将 prometheus 上传到一台单独的 Linux 机器上,执行解压操作

    ubuntu@VM-0-8-ubuntu:~$ lsapp  logs  Project  Prometheus  README.txt  tools  VueProjectubuntu@VM-0-8-ubuntu:~$ cd Prometheus/ubuntu@VM-0-8-ubuntu:~/Prometheus$ tar -xvf prometheus-2.15.2.linux-amd64.tar.gzubuntu@VM-0-8-ubuntu:~/Prometheus$ lsgrafana_6.5.3_amd64.deb  node_exporter-0.18.1.linux-amd64  prometheus-2.15.2.linux-amd64ubuntu@VM-0-8-ubuntu:~/Prometheus$ cd prometheus-2.15.2.linux-amd64/ubuntu@VM-0-8-ubuntu:~/Prometheus/prometheus-2.15.2.linux-amd64$ lsconsole_libraries  consoles  data  LICENSE  nohup.out  NOTICE  prometheus  prometheus.yml  promtool  tsdb
    
    • 1

    3、进入到解压后的文件夹中,修改配置文件,添加要监控的服务器信息192.168.1.26
    vi prometheus.yml

    4、在 scrape_configs 配置项下添加 Linux 监控的 job,其中IP 修改为上面部署 node_exporter 机器的 ip,端口号为 9100,注意缩进

    # my global config
    
    global:
    
      scrape_interval:     2s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
    
      evaluation_interval: 2s # Evaluate rules every 15 seconds. The default is every 1 minute.
    
      # scrape_timeout is set to the global default (10s).
    
    
    
    # Alertmanager configuration
    
    alerting:
    
      alertmanagers:
    
      - static_configs:
    
        - targets:
    
          # - alertmanager:9093
    
    
    
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    
    rule_files:
    
      # - "first_rules.yml"
    
      # - "second_rules.yml"
    
    
    
    # A scrape configuration containing exactly one endpoint to scrape:
    
    # Here it's Prometheus itself.
    
    scrape_configs:
    
      # The job name is added as a label `job=` 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:
    
    
    
      # 新增的服务器配置信息
    
      - job_name: 'node'
    
        static_configs:
    
        - targets: ['192.168.1.26:9100']
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71

    5、保存配置文件,启动 prometheus
    nohup ./prometheus &

    6、检查 nohup.out 日志,如果有以下信息,启动成功
    vi nohup.out
    通过反斜杠 ‘/Server is ready to receive’ 回车查询

    在这里插入图片描述

    7、在浏览器中访问部署的 prometheus:http://192.168.1.33:9090

    在这里插入图片描述

    8、点击菜单栏“Status-Targets”,看到页面中有如下 node 节点,代表 prometheus 和node_exporter 链接成功

    在这里插入图片描述

    04 部署 Grafana

    1、下载安装grafana(建议使用8.0.6版本,6.5.3有不兼容问题)
    sudo apt-get install -y adduser libfontconfig1
    wget https://dl.grafana.com/oss/release/grafana_6.5.3_amd64.deb
    sudo dpkg -i grafana_6.5.3_amd64.deb

    在这里插入图片描述

    2、启动 grafana
    systemctl start grafana-server

    3、在浏览器访问:http://192.168.1.33:3000/
    输入用户名/密码:admin/admin 登录

    在这里插入图片描述

    4、添加数据源,选择 prometheus

    在这里插入图片描述

    5、进行数据源配置,因为我的 prometheus 和 grafana 装在同一台机器上,所以 ip 写的是 localhost,如果没在一台机器上,写上 prometheus 的 IP

    在这里插入图片描述

    点击“save and test”,如果提示 success,代表配置成功

    6、官网查找监控模板
    打开 grafana 官网,查找官网提供的 prometheus 监控模板
    https://grafana.com/grafana/dashboards

    在这里插入图片描述

    点击 Linux 服务器监控的中文模板,记录该模板的 id:8919

    在这里插入图片描述

    7、在 grafana 系统页面中,通过 id 导入该模板,即可在 grafana 中看到 192.168.1.26 机器的性能监控数据

    在这里插入图片描述

    片

    8、将数据更新频率很具需要设置,就可以看到设置时间步长内的各项性能指标。包含了 CPU、Load、内存、网络、磁盘、IO 耗时等指标。监控数据永久保存,可以随时查看任意时间点内的历史统计数据,非常方便。

    在这里插入图片描述

    9、grafana服务启停

    设置开机自启:systemctl start grafana-server

    启动服务 sudo service grafana-server start

    重启 sudo service grafana-server restart

    停止服务 sudo service grafana-server stop

    05 MySQL 的监控

    1、下载 MySQL 的 exporter
    https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz

    2、上传至 MySQL 服务器上,解压包

    tar xvf mysqld_exporter-0.12.1.linux-amd64.tar.gz

    3、执行命令
    export DATA_SOURCE_NAME=‘root:admin1234@(192.168.1.30:3306)/’

    4、启动 mysql exporter
    进入到解压后的文件夹中,执行命令
    nohup ./mysqld_exporter &
    监控 nohup.out 日志,有如下日志代表成功

    在这里插入图片描述

    5、修改 prometheus 的配置文件 prometheus.yml vi prometheus.yml
    增加监控 MySQL 的 job(注意缩进格式)

    # my global config
    
    global:
    
      scrape_interval:     2s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
    
      evaluation_interval: 2s # Evaluate rules every 15 seconds. The default is every 1 minute.
    
      # scrape_timeout is set to the global default (10s).
    
    
    
    # Alertmanager configuration
    
    alerting:
    
      alertmanagers:
    
      - static_configs:
    
        - targets:
    
          # - alertmanager:9093
    
    
    
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    
    rule_files:
    
      # - "first_rules.yml"
    
      # - "second_rules.yml"
    
    
    
    # A scrape configuration containing exactly one endpoint to scrape:
    
    # Here it's Prometheus itself.
    
    scrape_configs:
    
      # The job name is added as a label `job=` 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:
    
    
    
      # 新增的服务器配置信息
    
      - job_name: 'node'
    
        static_configs:
    
        - targets: ['192.168.1.26:9100']
    
    
    
      # 新增的MySQL服务器配置信息
    
      - job_name: 'mysql'
    
        static_configs:
    
        - targets: ['192.168.1.30:9104']
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81

    targets 中的 IP 为 mysql_exporter 所在机器的 IP,端口号固定为 9104,重启 prometheus,进入 prometheus 的 UI 界面,在 status-targets 页面下,可以看到 MySQL exporter 的状态

    6、在 Grafana 中添加 MySQL 的监控模板

    在 grafana 官网模板中找到 MySQL 监控模板 Mysql Overview,id 为 7362,并导入到 Grafana 中(具体操作步骤参考上面导入 Linux 监控模板操作)


    资源分享

    下方这份完整的软件测试视频学习教程已经上传CSDN官方认证的二维码,朋友们如果需要可以自行免费领取 【保证100%免费】

    在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    日志的概念
    【Qt炫酷动画】7.浅谈动画设计的一些思考
    【推荐】智元兔AI:一款集写作、问答、绘画于一体的全能工具!
    使用LLM在KG上进行复杂的逻辑推理10.12
    计算机科学导论
    eval详解
    实践Docker部署
    项目进展(七)-焊接ADS1285及其外围电路,学习芯片的SPI部分
    算法训练营day45|动态规划 part07:完全背包 (LeetCode 70. 爬楼梯(进阶)、322. 零钱兑换、279.完全平方数)
    如何动态实现搜索框下方展示历史搜索记录?
  • 原文地址:https://blog.csdn.net/m0_67695717/article/details/127768307