Prometheus+Grafana普罗米修斯搭建+监控MySQL

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: ​ `Prometheus` 是 `Cloud Native Computing Foundation` 的一个监控系统项目, 集采集、监控、报警等特点于一体。​ `Prometheus`主要受启发于`Google`的`Brogmon`监控系统, 从`2012`年开始由前`Google`工程师在`Soundcloud`以开源软件的形式进行研发,`2017`年底发布了基于全新存储层的`2.0`版本,当前最新版本是`2.44.0`版本。

一,Prometheus

1.什么是Prometheus?

PrometheusCloud Native Computing Foundation 的一个监控系统项目, 集采集、监控、报警等特点于一体。

Prometheus主要受启发于GoogleBrogmon监控系统, 从2012年开始由前Google工程师在Soundcloud以开源软件的形式进行研发,2017年底发布了基于全新存储层的2.0版本,当前最新版本是2.44.0版本。

2.Prometheus架构

image-20230606173448476

3.prometheus具有那些特点?

  • 多维数据模型(由指标名称、键/值组合的时间序列);
  • 提供了一种强大而灵活的查询语言promsql;
  • 没有对分布式存储的依赖,单个服务器节点是自主的;
  • 主要支持时间序列集合的HTTP拉模模型,同时也提供PushGateway来满足;
  • 服务发现;
  • 自带UI,支持丰富多种图形和仪表板,还能与其他;
  • 支持分层和水平联合;

二,Prometheus搭建

IP 角色
192.168.2.4 prometheus服务器端
192.168.2.3 node_exporter客户端

1.二进制安装Prometheus

[root@server ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz
[root@server ~]# tar zxf prometheus-2.44.0.linux-amd64.tar.gz
[root@server ~]# mv prometheus-2.44.0.linux-amd64 /usr/local/prometheus
1.查看版本号
[root@server ~]# cd /usr/local/prometheus/
[root@server prometheus]# ./prometheus --version
prometheus, version 2.44.0 (branch: HEAD, revision: 1ac5131f698ebc60f13fe2727f89b115a41f6558)
  build user:       root@739e8181c5db
  build date:       20230514-06:18:11
  go version:       go1.20.4
  platform:         linux/amd64
  tags:             netgo,builtinassets,stringlabels
2.查看帮助文档
[root@server prometheus]# ./prometheus --help

2.prometheus.yml配置解释

# my global config
global:
  # 默认情况下,每15s拉取一次目标采样点数据。
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  # 每15秒评估一次规则。默认值为每1分钟。
  evaluation_interval: 15s # 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:
  # job名称会增加到拉取到的所有采样点上,同时还有一个instance目标服务的host:port标签也会增加到采样点上
  - job_name: 'prometheus'

    # 覆盖global的采样点,拉取时间间隔5s
    scrape_interval: 5s
    static_configs:
    - targets: ['localhost:9090']

3.升级为系统服务

# 启动服务
cd /usr/lib/systemd/system
vi prometheus.service

[Unit]
  Description=https://prometheus.io

  [Service]
  Restart=on-failure
  ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090

  [Install]                      
  WantedBy=multi-user.target

#保存退出

其他选项解释:

常用选项解释:
# 指定配置文件
--config.file="prometheus.yml"
# 默认指定监听地址端口,可修改端口
--web.listen-address="0.0.0.0:9090" 
# 最大连接数
--web.max-connections=512
# tsdb数据存储的目录,默认当前data/
--storage.tsdb.path="data/"
# premetheus 存储数据的时间,默认保存15天
--storage.tsdb.retention=15d 
# 通过命令热加载无需重启 curl -XPOST 192.168.2.45:9090/-/reload
--web.enable-lifecycle
# 可以启用 TLS 或 身份验证 的配置文件的路径
--web.config.file=""

启动选项了解:./prometheus --help

4.刷新system文件,启动

systemctl daemon-reload
systemctl start prometheus

5.访问测试

IP:9090

image-20230606214543919

三,客户端node_exporter搭建

1.监控目的Linux安装node_exporter

[root@server ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
[root@server ~]# tar xf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/
[root@server ~]# cd /usr/local/
[root@server ~]# mv node_exporter-1.1.2.linux-amd64/ node_exporter

2.添加为系统服务

[root@server ~]# vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target 

[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

# 启动node_exporter
systemctl daemon-reload
systemctl start node_exporter

3.prometheus服务器端添加监控项

[root@server prometheus]# cat prometheus.yml 
# my global config
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).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['192.168.2.4:9090']

  - job_name: 'linux'
    static_configs:
    - targets: ['192.168.2.4:9100','192.168.2.3:9100'] # 多个用,分开

# 添加上面三行

4.重启系统普罗米修斯

[root@server ~]#  systemctl restart prometheus.service

5.监控界面

image-20230607120658060

四,监控MySQL

1.安装mysqld-exporter

[root@VM_2-44 ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
[root@VM_2-44 ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/
[root@VM_2-44 /usr/local]# mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
[root@VM_2-44 /usr/local/mysqld_exporter]# vi .my.cnf
[client]
host=192.168.2.3
user=root
password=123456
port=3306

2.启动mysqld-exporter服务

[root@VM_2-44 /usr/local/mysqld_exporter]# ./mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &
[root@VM_2-44 /usr/local/mysqld_exporter]# ps -ef |grep exporter
root       3447   3398  0 01:31 pts/1    00:00:02 ./node_exporter
root       4647   3398  0 02:13 pts/1    00:00:00 ./mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
root       4654   3398  0 02:13 pts/1    00:00:00 grep --color=auto exporter
[root@VM_2-44 /usr/local/mysqld_exporter]# ss -lntp |grep 4647
LISTEN     0      128         :::9104                    :::*                   users:(("mysqld_exporter",pid=4647,fd=3))
[root@VM_2-44 /usr/local/mysqld_exporter]# 

# 启动后会监听9104端口

3.普罗米修斯配置文件添加监控项

[root@VM_2-45 /usr/local/prometheus]# vi prometheus.yml 
  - job_name: 'mysql'
    static_configs:
    - targets: ['192.168.2.3:9104']

4.重启普罗米修斯

[root@VM_2-45 /usr/local/prometheus]# systemctl restart prometheus.service

5.查看状态

image-20230607121855953

五,grafana展示prometheus数据

1.在prometheus安装grafana

wget https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/Packages/grafana-7.4.3-1.x86_64.rpm

[root@VM_2-45 ~]# yum install initscripts fontconfig
[root@VM_2-45 ~]# yum install -y grafana-7.4.3-1.x86_64.rpm
[root@VM_2-45 ~]# systemctl start grafana-server.service

2.访问grafana

启动后访问地址:ip:3000
初始用户名和密码都是admin

image-20230607175213818

3.添加Prometheus数据源

Configuration -> Data Sources ->add data source -> Prometheus

image-20230607175440453

​ 添加prometheus服务器

image-20230607175652523

4.添加dashboard Linux基础数据展示

image-20230607193647608

​ 导入模板8919

image-20230607193931544

​ 选择数据源

image-20230607194200334

5.查看dashboard

Dashboards ->Manage

image-20230607194358473

六,grafana展示MySQL信息

1.设置数据源

Configuration -> Data Sources ->add data source -> MySQL

image-20230607194548093

2.数据库上授权用户

image-20230607194824215

3.导入下载的dashboard,数据源现在刚刚创建的

https://pan.baidu.com/s/1GBzogDLsYS3IvwH4WbdPLw 提取码:ef6e

image-20230607195029118

4.查看效果

image-20230607195131761

相关实践学习
通过可观测可视化Grafana版进行数据可视化展示与分析
使用可观测可视化Grafana版进行数据可视化展示与分析。
目录
相关文章
|
2月前
|
存储 数据采集 Prometheus
Grafana Prometheus Altermanager 监控系统
Grafana、Prometheus 和 Alertmanager 是一套强大的开源监控系统组合。Prometheus 负责数据采集与存储,Alertmanager 处理告警通知,Grafana 提供可视化界面。本文简要介绍了这套系统的安装配置流程,包括各组件的下载、安装、服务配置及开机自启设置,并提供了访问地址和重启命令。适用于希望快速搭建高效监控平台的用户。
176 20
|
2月前
|
Prometheus 监控 Cloud Native
Prometheus+Grafana监控Linux主机
通过本文的步骤,我们成功地在 Linux 主机上使用 Prometheus 和 Grafana 进行了监控配置。具体包括安装 Prometheus 和 Node Exporter,配置 Grafana 数据源,并导入预设的仪表盘来展示监控数据。通过这种方式,可以轻松实现对 Linux 主机的系统指标监控,帮助及时发现和处理潜在问题。
233 7
|
2月前
|
Prometheus 运维 监控
Prometheus+Grafana+NodeExporter:构建出色的Linux监控解决方案,让你的运维更轻松
本文介绍如何使用 Prometheus + Grafana + Node Exporter 搭建 Linux 主机监控系统。Prometheus 负责收集和存储指标数据,Grafana 用于可视化展示,Node Exporter 则采集主机的性能数据。通过 Docker 容器化部署,简化安装配置过程。完成安装后,配置 Prometheus 抓取节点数据,并在 Grafana 中添加数据源及导入仪表盘模板,实现对 Linux 主机的全面监控。整个过程简单易行,帮助运维人员轻松掌握系统状态。
330 3
|
2月前
|
Prometheus 监控 Cloud Native
无痛入门Prometheus:一个强大的开源监控和告警系统,如何快速安装和使用?
Prometheus 是一个完全开源的系统监控和告警工具包,受 Google 内部 BorgMon 系统启发,自2012年由前 Google 工程师在 SoundCloud 开发以来,已被众多公司采用。它拥有活跃的开发者和用户社区,现为独立开源项目,并于2016年加入云原生计算基金会(CNCF)。Prometheus 的主要特点包括多维数据模型、灵活的查询语言 PromQL、不依赖分布式存储、通过 HTTP 拉取时间序列数据等。其架构简单且功能强大,支持多种图形和仪表盘展示模式。安装和使用 Prometheus 非常简便,可以通过 Docker 快速部署,并与 Grafana 等可
655 2
|
3月前
|
数据采集 Prometheus 监控
监控堆外第三方监控工具Grafana
监控堆外第三方监控工具Grafana
112 5
|
3月前
|
存储 Prometheus 监控
监控堆外第三方监控工具Prometheus
监控堆外第三方监控工具Prometheus
88 3
|
3月前
|
存储 Prometheus 运维
在云原生环境中,阿里云ARMS与Prometheus的集成提供了强大的应用实时监控解决方案
在云原生环境中,阿里云ARMS与Prometheus的集成提供了强大的应用实时监控解决方案。该集成结合了ARMS的基础设施监控能力和Prometheus的灵活配置及社区支持,实现了全面、精准的系统状态、性能和错误监控,提升了应用的稳定性和管理效率。通过统一的数据视图和高级查询功能,帮助企业有效应对云原生挑战,促进业务的持续发展。
110 3
|
3月前
|
Prometheus 监控 Cloud Native
在 HBase 集群中,Prometheus 通常监控哪些类型的性能指标?
在 HBase 集群中,Prometheus 监控关注的核心指标包括 Master 和 RegionServer 的进程存在性、RPC 请求数、JVM 内存使用率、磁盘和网络错误、延迟和吞吐量、资源利用率及 JVM 使用信息。通过 Grafana 可视化和告警规则,帮助管理员实时监控集群性能和健康状况。
|
3月前
|
Prometheus 运维 监控
智能运维实战:Prometheus与Grafana的监控与告警体系
【10月更文挑战第27天】在智能运维中,Prometheus和Grafana的组合已成为监控和告警体系的事实标准。Prometheus负责数据收集和存储,支持灵活的查询语言PromQL;Grafana提供数据的可视化展示和告警功能。本文介绍如何配置Prometheus监控目标、Grafana数据源及告警规则,帮助运维团队实时监控系统状态,确保稳定性和可靠性。
448 0
|
3月前
|
Prometheus 运维 监控
智能运维实战:Prometheus与Grafana的监控与告警体系
【10月更文挑战第26天】Prometheus与Grafana是智能运维中的强大组合,前者是开源的系统监控和警报工具,后者是数据可视化平台。Prometheus具备时间序列数据库、多维数据模型、PromQL查询语言等特性,而Grafana支持多数据源、丰富的可视化选项和告警功能。两者结合可实现实时监控、灵活告警和高度定制化的仪表板,广泛应用于服务器、应用和数据库的监控。
481 3