Percona 监控和管理, 主要是为了监控 MySQL和 MongoDB性能的开源平台, 专业的数据库监控,随着用户的需求,后期可监控 proxysql
其他监控
Lepus (天兔)
1) 图形化界面相对来说较楼
2) 监控项少
3) 官方对其停止维护与更新
Zabbix
1) 图形化简陋
PMM:
1) web 界面比较宝高逼格
2) 监控项多
3) 连接、线程、
pmm-mysql-queries-0 用于收集MySQL查询性能,将其数据发送至 PMM Server 上 QAN API上
pmm-admin 客户端命令行工具,用于添加监控和删除监控
node_exporter 用于搜集系统性能的数据。
mysqld_exporter 用于搜集mysql 的性能数据
QAN API 获取 监控数据的接收接口
QAN App 对 数据查询并进行分析
PMM Landing Page 生成监控数据的页面,Grafana(第三方的图形展示界面)提供页面
Orchestrator 用于提供MySQL复制到拓扑关系图
Prometheus 普罗米修斯, 用于做存储
Grafana 用于生成比较好的显示效果, 仪表板 第三方的 图形展示界面
Consul API 注册中心API接口
Consul web ui 注册中心web 界面
PMM 原理:
PMM Client 通过 pmm-admin 将 mysql添加为监控项,当 用户在插入、删除、修改、查询数据时, 被 agent 代理收集到信息,将信息发送到 PMM server中 由QAN Api 接口接收数据信息,将其转发至 QAN App 进行数据分析,将分析好的数据 ,通过 PMMLanding page 发布,PMM Landing page 将数据交给 Grafana 来处理,最后形成炫酷的监控界面。
exporter 将收集的系统信息,交给 Promenade 进行存储,然后将其传输给 Grafana 形成炫酷的图形化界面,通过 PMM Landing page 发布为 web 页面
pmm-admin ,用于添加、删除、启动、停止、维护监控项
实验环境:
PMM Client : 192.168.116.103
所需工具:
mysql-community-client-5.6.44-2.el6.x86_64.rpm
mysql-community-common-5.6.44-2.el6.x86_64.rpm
mysql-community-libs-5.6.44-2.el6.x86_64.rpm
mysql-community-server-5.6.44-2.el6.x86_64.rpm
percona-toolkit-3.1.0-2.el7.x86_64.rpm
pmm-client-1.17.1-1.el7.x86_64.rpm
percona-release-0.1-6.noarch.rpm
PMM Server: 192.168.116.104
所需 Docker 环境支持
- ### 安装docker
[root@localhost ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum-config-manager --add-repo=http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@localhost ~]# yum makecache fast
[root@localhost ~]# yum -y install docker-ce
[root@localhost ~]# systemctl start docker
安装如报错: https://blog.csdn.net/RunzIyy/article/details/104617033
可参考:https://blog.csdn.net/weixin_43557605/article/details/104447317
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker pull percona/pmm-server
[root@localhost ~]# docker create -v /opt/consul/data -v /opt/prometheus/data -v /var/lib/mysql -v /var/lib/grafana --name pmm-data percona/pmm-server
c0d37cca277837f5c8e1b2f031e44180394ed91a88702ed6a2850812c29cc165
解释:
docker create 命令字,创建容器
-v 初始化数据卷的容器
--name 该选项为你可以用于引用 Docker 网路中的容器的的名称
percona/pmm-server 导出容器的名称版本
如果出错:
docker rm -f pmm-data
[root@localhost ~]# docker run -d -p 80:80 --volumes-from pmm-data --name pmm-server --restart always -e SERVER_USER=test -e SERVER_PASSWORD=123456 percona/pmm-server
3c79fa315cea3e87ca45c27a6f43679ce7e5813c959db93fd1c6294903c1c880
解释:
docker run 命令字, 从守护程序在镜像中运行程序
-d 后台启动容器
-p 映射 PMM 服务器的 ui 端口
-volumes-form 从 pmm-adta容器中装入卷
---name 引用Docker 网络中的容器并自定义名称
--restart 重启启动容器
SERVER_USER=test 设置连接用户
SERVER_PASSWORD 设置连接用户密码
如果报错:
docker rm -f pmm-server
http://192.168.116.104
[root@localhost ~]# rpm -ivh percona-release-latest.noarch.rpm
[root@localhost ~]# rpm -ivh pmm-client-1.17.1-1.el7.x86_64.rpm
[root@localhost ~]# tar -xf mysql-5.6.bundle.tar
[root@localhost ~]# cd mysql
[root@localhost mysql]# ls
mysql-community-client-5.6.44-2.el6.x86_64.rpm mysql-community-libs-5.6.44-2.el6.x86_64.rpm
mysql-community-common-5.6.44-2.el6.x86_64.rpm mysql-community-server-5.6.44-2.el6.x86_64.rpm
[root@localhost mysql]# pwd
/root/mysql
[root@localhost mysql]# yum -y localinstall *.rpm
# localinstall 安装本地 rpm 包,依赖关系通过yum 解决
# install 通过网络下载,安装
[root@localhost ~]# yum -y localinstall percona-toolkit-3.1.0-2.el7.x86_64.rpm
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# mysqladmin -uroot password 123456
Warning: Using a password on the command line interface can be insecure.
[root@localhost ~]# pmm-admin config --server 192.168.116.104 --server-user test --server-password 123456
OK, PMM server is alive.
PMM Server | 192.168.116.104 (password-protected) # 服务端地址
Client Name | localhost.localdomain # 客户端名称
Client Address | 192.168.116.103 # 客户端地址
以下命令需连接 server 端 方可执行
pmm-admin ping
例:
[root@localhost ~]# pmm-admin ping
Warning: It is recommended to use the same version on both PMM Server and Client, otherwise some features will not work correctly.
Please upgrade your PMM Client by following the instructions from https://www.percona.com/doc/percona-monitoring-and-management/deploy/index.html#updating
OK, PMM server is alive.
PMM Server | 192.168.116.104 (password-protected)
Client Name | localhost.localdomain
Client Address | 192.168.116.103
pmm-admin check-network
pmm-admin add 监控项
例子: 添加主机监控
[root@localhost ~]# pmm-admin add linux:metrics
Warning: It is recommended to use the same version on both PMM Server and Client, otherwise some features will not work correctly.
Please upgrade your PMM Client by following the instructions from https://www.percona.com/doc/percona-monitoring-and-management/deploy/index.html#updating
OK, now monitoring this system.
pmm-admin rm 监控项
pmm-admin list
例子:
[root@localhost ~]# pmm-admin list
…………
-------------- ---------------------- ----------- -------- ------------ --------
SERVICE TYPE NAME LOCAL PORT RUNNING DATA SOURCE OPTIONS
-------------- ---------------------- ----------- -------- ------------ --------
linux:metrics localhost.localdomain 42000 YES -
pmm-admin info
[root@localhost ~]# pmm-admin info
pmm-admin 1.17.1
PMM Server | 192.168.116.104 (password-protected)
Client Name | localhost.localdomain
Client Address | 192.168.116.103
Service Manager | linux-systemd
Go Version | 1.10.1
Runtime Info | linux/amd64
pmm-admin show-passwords
pmm-admin config
[root@localhost ~]# pmm-admin config
OK, PMM server is alive.
PMM Server | 192.168.116.104 (password-protected)
Client Name | localhost.localdomain
Client Address | 192.168.116.103
pmm-admin start/stop 监控项
PMM-CLient
[root@localhost ~]# vim /etc/my.cnf
# 在末尾添加
log_output=file
slow_query_log=ON
long_query_time=0
log_slow_rate_limit=100
log_slow_rate_type=query
log_slow_admin_statements=ON
log_slow_slave_statements=ON
slow_query_log_always_write_time=1
slow_query_log_use_global_control=1
innodb_monitor_enable=ON
userstat=1
解释:
log_output=file # 将日志存储文件
slow_query_log=ON # 开启慢查询日志
long_query_time=0 # 慢查询阈值
log_slow_rate_limit=100 # 日志慢速速率限制
log_slow_rate_type=query # 日志慢速率类型
log_slow_admin_statements=ON # 登录慢查询语句
log_slow_slave_statements=ON
slow_query_log_always_write_time=1 # 慢查询日志写入的时间间隔
slow_query_log_use_global_control=1 # 记录全局慢查询日志
innodb_monitor_enable=ON # 启用 innodb 来监控 mysql的性能
userstat=1 # 记录用户登录失败的次数
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# mysql -uroot -p123456
mysql> GRANT ALL ON *.* TO 'pmm'@'localhost' IDENTIFIED BY '12345678';
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# pmm-admin add mysql:metrics --user pmm --password 12345678 --host 192.168.116.103 --port 3306
Warning: It is recommended to use the same version on both PMM Server and Client, otherwise some features will not work correctly.
Please upgrade your PMM Client by following the instructions from https://www.percona.com/doc/percona-monitoring-and-management/deploy/index.html#updating
OK, now monitoring MySQL metrics using DSN pmm:***@tcp(192.168.116.103:3306)
命令解释:
pmm-admin add # pmm-admin 命令字 add 添加监控项
mysql:metrics # 监控项,表示 监控mysql
--user pmm # 指定授权用户,监控么,要么获取数据
--password 123456 # 指定登录密码
--host 192.168.116.103 # 指定数据库地址
--port 3306 # 指定端口号
[root@localhost ~]# pmm-admin add mysql --query-source auto --user pmm --password 12345678 --host 192.168.116.103 --port 3306
Warning: It is recommended to use the same version on both PMM Server and Client, otherwise some features will not work correctly.
Please upgrade your PMM Client by following the instructions from https://www.percona.com/doc/percona-monitoring-and-management/deploy/index.html#updating
[linux:metrics] OK, already monitoring this system.
[mysql:metrics] OK, already monitoring MySQL metrics.
[mysql:queries] OK, now monitoring MySQL queries from slowlog using DSN pmm:***@tcp(192.168.116.103:3306)