PMM 对MYSQL 的监控配制
系统选择: centos 7.2
关闭防火墙:
systemctl stop firewalld.service
systemctl disable firewalld.service
起用转发:
# vi /usr/lib/sysctl.d/00-system.conf
添加如下代码:
net.ipv4.ip_forward=1
重启network服务
# systemctl restart network
查看是否修改成功
# sysctl net.ipv4.ip_forward
如果返回为“net.ipv4.ip_forward = 1”则表示成功了
pmm-server 安装:
pmm官方文档:
Pmm 组成: https://www.percona.com/doc/percona-monitoring-and-management/architecture.html
PMM 安装: https://www.percona.com/doc/percona-monitoring-and-management/deploy/server/docker.html#run-server-docker
相关开源项目:
https://www.sqlite.org/atomiccommit.html
https://github.com/prometheus
1.安装DOCKER,RPM包的名字是docker-io
yum install docker -y
2.启动docker
service docker start
ps -ef |grep docker
3.创建容器的数据磁盘
docker create \
-v /opt/prometheus/data \
-v /opt/consul-data \
-v /var/lib/mysql \
-v /var/lib/grafana \
--name pmm-data \
docker.io/percona/pmm-server /bin/true
//默认本地不存pmm-server,会从官网下载 ,但是会很慢
容器卷在宿主机的目录位置:
docker inspect pmm-data
"Mounts": [
{
"Name": "134874af6736c9065c504d084eb0b754507da23a212cd90524d35463dcff8c54",
"Source": "/var/lib/docker/volumes/134874af6736c9065c504d084eb0b754507da23a212cd90524d35463dcff8c54/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "3d03268806f49143f8051aefc8ebef047ceeeeea24c5fe2828e06e0b08b36f6e",
"Source": "/var/lib/docker/volumes/3d03268806f49143f8051aefc8ebef047ceeeeea24c5fe2828e06e0b08b36f6e/_data",
"Destination": "/opt/consul-data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "47dde5e315f8123018a485d8a922d060761a508b9958bc5e8c38f4b934152321",
"Source": "/var/lib/docker/volumes/47dde5e315f8123018a485d8a922d060761a508b9958bc5e8c38f4b934152321/_data",
"Destination": "/opt/prometheus/data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "4faad60a6619be2f2aa29c34dd8630427cd70810d849a21bc26733b3970dfb6b",
"Source": "/var/lib/docker/volumes/4faad60a6619be2f2aa29c34dd8630427cd70810d849a21bc26733b3970dfb6b/_data",
"Destination": "/var/lib/grafana",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
{
"Name": "134874af6736c9065c504d084eb0b754507da23a212cd90524d35463dcff8c54",
"Source": "/var/lib/docker/volumes/134874af6736c9065c504d084eb0b754507da23a212cd90524d35463dcff8c54/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "3d03268806f49143f8051aefc8ebef047ceeeeea24c5fe2828e06e0b08b36f6e",
"Source": "/var/lib/docker/volumes/3d03268806f49143f8051aefc8ebef047ceeeeea24c5fe2828e06e0b08b36f6e/_data",
"Destination": "/opt/consul-data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "47dde5e315f8123018a485d8a922d060761a508b9958bc5e8c38f4b934152321",
"Source": "/var/lib/docker/volumes/47dde5e315f8123018a485d8a922d060761a508b9958bc5e8c38f4b934152321/_data",
"Destination": "/opt/prometheus/data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "4faad60a6619be2f2aa29c34dd8630427cd70810d849a21bc26733b3970dfb6b",
"Source": "/var/lib/docker/volumes/4faad60a6619be2f2aa29c34dd8630427cd70810d849a21bc26733b3970dfb6b/_data",
"Destination": "/var/lib/grafana",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
4.创建容器的运行实例:
docker run -d \
-p 80:80 \
--volumes-from pmm-data \
--name pmm-server \
--restart always \
percona/pmm-server:1.2.0
容器卷在宿主机的目录位置:
docker inspect pmm-server
"Mounts": [
{
"Name": "47dde5e315f8123018a485d8a922d060761a508b9958bc5e8c38f4b934152321",
"Source": "/var/lib/docker/volumes/47dde5e315f8123018a485d8a922d060761a508b9958bc5e8c38f4b934152321/_data",
"Destination": "/opt/prometheus/data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "4faad60a6619be2f2aa29c34dd8630427cd70810d849a21bc26733b3970dfb6b",
"Source": "/var/lib/docker/volumes/4faad60a6619be2f2aa29c34dd8630427cd70810d849a21bc26733b3970dfb6b/_data",
"Destination": "/var/lib/grafana",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "134874af6736c9065c504d084eb0b754507da23a212cd90524d35463dcff8c54",
"Source": "/var/lib/docker/volumes/134874af6736c9065c504d084eb0b754507da23a212cd90524d35463dcff8c54/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "3d03268806f49143f8051aefc8ebef047ceeeeea24c5fe2828e06e0b08b36f6e",
"Source": "/var/lib/docker/volumes/3d03268806f49143f8051aefc8ebef047ceeeeea24c5fe2828e06e0b08b36f6e/_data",
"Destination": "/opt/consul-data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
{
"Name": "47dde5e315f8123018a485d8a922d060761a508b9958bc5e8c38f4b934152321",
"Source": "/var/lib/docker/volumes/47dde5e315f8123018a485d8a922d060761a508b9958bc5e8c38f4b934152321/_data",
"Destination": "/opt/prometheus/data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "4faad60a6619be2f2aa29c34dd8630427cd70810d849a21bc26733b3970dfb6b",
"Source": "/var/lib/docker/volumes/4faad60a6619be2f2aa29c34dd8630427cd70810d849a21bc26733b3970dfb6b/_data",
"Destination": "/var/lib/grafana",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "134874af6736c9065c504d084eb0b754507da23a212cd90524d35463dcff8c54",
"Source": "/var/lib/docker/volumes/134874af6736c9065c504d084eb0b754507da23a212cd90524d35463dcff8c54/_data",
"Destination": "/var/lib/mysql",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
},
{
"Name": "3d03268806f49143f8051aefc8ebef047ceeeeea24c5fe2828e06e0b08b36f6e",
"Source": "/var/lib/docker/volumes/3d03268806f49143f8051aefc8ebef047ceeeeea24c5fe2828e06e0b08b36f6e/_data",
"Destination": "/opt/consul-data",
"Driver": "local",
"Mode": "",
"RW": true,
"Propagation": ""
}
],
更改面板数据sqlite库存储类型为MYSQL(容器自带)
[root@workstation2017 ~]# docker exec -i -t pmm-server /bin/bash
[root@86b5c5955521 opt]# vi /etc/grafana/grafana.ini
查/sqlite 改为MYSQL 存储
type=mysql
host=127.0.0.1:3306
name=grafana
user=root
password =
在容器进入mysql客户端,创建数据库grafana,
create database grafana;
生效:
docker restart pmm-server
// 默认面板监控数据数据保在 /var/lib/grafana/grafana.db
PMM client 安装:
[root@workstation2017 ~]# service mysql start
Redirecting to /bin/systemctl start mysql.service
下载与PMM SERVER 一致的 PMM client
https://www.percona.com/downloads/pmm-client/
配制:
[root@workstation2017 ~]# pmm-admin config --server 192.168.79.220
OK, PMM server is alive.
PMM Server | 192.168.79.220
Client Name | workstation2017
Client Address | 192.168.79.220
开始监控:
pmm-admin add mysql --query-source perfschema --user root --password xx
WEB访问页面并配制相关值:
http://192.168.79.220/graph
data sources--->edit data source
config:
填入:
name:prometheus
type:prometheus
http settings:加入
http://127.0.0.1:9090/prometheus
dashboards-->import
点选导入import json文件
操作目的:监控指定的Metrics,减少系统的统计负载,并采用MYSQL作为存储后端
详细操作如下:
json文件容器导出到宿主机的目录上,并在WEB 面板中导入
[root@f3e8318c8d7c dashboards]# pwd
/usr/share/percona-dashboards/dashboards
[root@f3e8318c8d7c dashboards]# ls
Amazon_RDS_OS_Metrics.json MongoDB_Overview.json MySQL_Performance_Schema.json Prometheus.json
Cross_Server_Graphs.json MongoDB_ReplSet.json MySQL_Query_Response_Time.json ProxySQL_Overview.json
Disk_Performance.json MongoDB_RocksDB.json MySQL_Replication.json Summary_Dashboard.json
Disk_Space.json MongoDB_WiredTiger.json MySQL_Table_Statistics.json System_Overview.json
MariaDB.json MySQL_InnoDB_Metrics.json MySQL_TokuDB_Metrics.json Trends_Dashboard.json
MongoDB_Cluster_Summary.json MySQL_InnoDB_Metrics_Advanced.json MySQL_User_Statistics.json
MongoDB_InMemory.json MySQL_MyISAM_Metrics.json PXC_Galera_Cluster_Overview.json
MongoDB_MMAPv1.json MySQL_Overview.json PXC_Galera_Graphs.json
拷到宿主机的目录中:
[root@workstation2017 ~]# docker cp f3e8318c8d7c:/usr/share/percona-dashboards/dashboards /soft/
然后用XSHELL 拷到WINDOW目录下
在主机WEB界面中
在导入框中加入MySQL_InnoDB_Metrics.json
dashboard ---> import---> MySQL_InnoDB_Metrics.json
即可全部配制完成
PMM-SERVER 与 PMM-CLIENT 互联检测
gui: http://192.168.79.220:80/prometheus/targets
command: pmm-admin check-network
pmm-admin list
EG:
[root@workstation2017 ~]# pmm-admin check-network
PMM Network Status
Server Address | 192.168.79.220
Client Address | 192.168.79.220
* System Time
NTP Server (0.pool.ntp.org) | 2017-07-24 22:57:08 -0400 EDT
PMM Server | 2017-07-25 02:57:08 +0000 GMT
PMM Client | 2017-07-24 22:57:08 -0400 EDT
PMM Server Time Drift | OK
PMM Client Time Drift | OK
PMM Client to PMM Server Time Drift | OK
* Connection: Client --> Server
-------------------- -------
SERVER SERVICE STATUS
-------------------- -------
Consul API OK
Prometheus API OK
Query Analytics API OK
Connection duration | 465.152µs
Request duration | 1.000382ms
Full round trip | 1.465534ms
* Connection: Client <-- Server
-------------- ---------------- --------------------- ------- ---------- ---------
SERVICE TYPE NAME REMOTE ENDPOINT STATUS HTTPS/TLS PASSWORD
-------------- ---------------- --------------------- ------- ---------- ---------
linux:metrics workstation2017 192.168.79.220:42000 OK YES -
mysql:metrics workstation2017 192.168.79.220:42002 OK YES -