news 2026/7/12 7:57:14

Prometheus监控平台搭建,性能测试必备技能!

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Prometheus监控平台搭建,性能测试必备技能!

01Prometheus 监控平台部署

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

AI写代码

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

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

  1. # my global config

  2. global:

  3. scrape_interval: 2s # Set the scrape interval to every 15 seconds. Default is every 1 minute.

  4. evaluation_interval: 2s # Evaluate rules every 15 seconds. The default is every 1 minute.

  5. # scrape_timeout is set to the global default (10s).

  6. # Alertmanager configuration

  7. alerting:

  8. alertmanagers:

  9. - static_configs:

  10. - targets:

  11. # - alertmanager:9093

  12. # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.

  13. rule_files:

  14. # - "first_rules.yml"

  15. # - "second_rules.yml"

  16. # A scrape configuration containing exactly one endpoint to scrape:

  17. # Here it's Prometheus itself.

  18. scrape_configs:

  19. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  20. - job_name: 'prometheus'

  21. # metrics_path defaults to '/metrics'

  22. # scheme defaults to 'http'.

  23. static_configs:

  24. - targets: ['localhost:9090']

  25. - job_name: 'node'

  26. static_configs:

  27. # 新增的服务器配置信息

  28. - job_name: 'node'

  29. static_configs:

  30. - targets: ['192.168.1.26:9100']

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.ymlvi prometheus.yml
增加监控 MySQL 的 job(注意缩进格式)

  1. # my global config

  2. global:

  3. scrape_interval: 2s # Set the scrape interval to every 15 seconds. Default is every 1 minute.

  4. evaluation_interval: 2s # Evaluate rules every 15 seconds. The default is every 1 minute.

  5. # scrape_timeout is set to the global default (10s).

  6. # Alertmanager configuration

  7. alerting:

  8. alertmanagers:

  9. - static_configs:

  10. - targets:

  11. # - alertmanager:9093

  12. # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.

  13. rule_files:

  14. # - "first_rules.yml"

  15. # - "second_rules.yml"

  16. # A scrape configuration containing exactly one endpoint to scrape:

  17. # Here it's Prometheus itself.

  18. scrape_configs:

  19. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  20. - job_name: 'prometheus'

  21. # metrics_path defaults to '/metrics'

  22. # scheme defaults to 'http'.

  23. static_configs:

  24. - targets: ['localhost:9090']

  25. - job_name: 'node'

  26. static_configs:

  27. # 新增的服务器配置信息

  28. - job_name: 'node'

  29. static_configs:

  30. - targets: ['192.168.1.26:9100']

  31. # 新增的MySQL服务器配置信息

  32. - job_name: 'mysql'

  33. static_configs:

  34. - targets: ['192.168.1.30:9104']

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

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

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

感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/12 0:34:26

[HNCTF 2022 Week1]easync

第一次打CTF——PWN篇学习笔记9niuyingyingniuyingying-virtual-machine:~$ nc node5.anna.nssctf.cn 29257 ls bin dev easync flag gift lib lib32 lib64 libexec libx32 nothing cat nothing cat: nothing: Is a directory cd nothing ls flag1 cat flag1 nssctf{Nc_ ^C niu…

作者头像 李华
网站建设 2026/7/12 6:42:31

Ultravox终极指南:10个步骤掌握AI音频生成技术

Ultravox终极指南&#xff1a;10个步骤掌握AI音频生成技术 【免费下载链接】ultravox 项目地址: https://gitcode.com/GitHub_Trending/ul/ultravox Ultravox是基于Transformer架构的开源多模态语音AI模型&#xff0c;专门为高质量的音频生成和处理而设计。该项目整合了…

作者头像 李华
网站建设 2026/7/11 19:19:29

学习 Python,用哪个编辑器比较好?

对于初学者来说&#xff0c;选择合适的编程环境是开启编程之旅的第一步。Python 作为一门功能强大且应用广泛的编程语言&#xff0c;拥有丰富的开发工具和编辑器供我们选择。但面对众多选项&#xff0c;究竟哪一款才是最适合新手的呢&#xff1f;本文将带你深入了解几种常用的 …

作者头像 李华
网站建设 2026/7/11 20:48:28

如何高效地分析问卷调查的数据?

在当今信息爆炸的时代&#xff0c;数据已经成为了企业决策的重要依据之一。无论是市场调研、用户满意度调查还是学术研究&#xff0c;问卷调查都是获取一手数据的重要手段。然而&#xff0c;如何从海量的数据中提炼出有价值的信息&#xff0c;成为了一个技术活儿。今天&#xf…

作者头像 李华