pmm docker-compose 运行试用
pmm 是一个很不错的mysql、mongo、postgresql 数据库监控平台,基于prometheus、grafana、exporter 算是一个比较完整
的数据库分析平台
参考架构图
环境准备
对于pg 以及mysql 的运行基于docker 官方镜像,添加了pmm client 包,同时为了添加指标,添加了gogs(git 服务),pgloader
mysql 数据迁移到pg,没有配置node exporter
- docker-compose文件
version: "3"
services:
pgloader-mysql:
image: dimitri/pgloader
command: pgloader mysql://root:dalongrong@mysql/gogs postgresql://postgres:dalong@postgres:5432/appdemo
gogs:
image: gogs/gogs
ports:
- "10022:22"
- "3000:3000"
pmmserver:
image: percona/pmm-server:1.17
ports:
- "80:80"
mysqlexporter:
image: prom/mysqld-exporter
ports:
- "9104:9104"
environment:
- "DATA_SOURCE_NAME=root:dalongrong@(mysql:3306)/"
mysql:
build:
context: ./mysql
dockerfile: Dockerfile
ports:
- 3306:3306
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
environment:
MYSQL_ROOT_PASSWORD: dalongrong
MYSQL_DATABASE: gogs
MYSQL_USER: gogs
MYSQL_PASSWORD: dalongrong
TZ: Asia/Shanghai
postgres:
build:
context: ./pg
dockerfile: Dockerfile
ports:
- "5432:5432"
environment:
- "POSTGRES_PASSWORD:dalong"
pgexporter:
image: wrouesnel/postgres_exporter:latest
ports:
- 9187:9187
environment:
- DATA_SOURCE_NAME=postgresql://postgres:dalong@postgres:5432/postgres_exporter?sslmode=disable
- pg dockerfile
FROM postgres:latest
RUN set -ex; \
apt-get update; \
apt-get install -y gnupg apt-transport-https; \
echo 'deb https://repo.percona.com/apt stretch main' > /etc/apt/sources.list.d/percona.list; \
apt-get update && apt-get install -y --allow-unauthenticated pmm-client; \
apt-get remove --purge -y gnupg apt-transport-https; \
apt-get autoremove -y --purge; \
rm -rf /var/lib/apt/lists/* \
true
COPY init.sql /docker-entrypoint-initdb.d/
COPY initpmm.sh /root/
说明:
主要是initpmm.sh 文件,进行exporter metrics 注册
#!/bin/sh
while ! pmm-admin config --client-name pg1 --server pmmserver
do
sleep 1
done
pmm-admin add external:metrics postgresql-demo pgexporter:9187
- mysql dockerfile
FROM mysql:5.7.16
RUN set -ex; \
apt-get update; \
apt-get install -y gnupg apt-transport-https; \
echo 'deb https://repo.percona.com/apt stretch main' > /etc/apt/sources.list.d/percona.list; \
apt-get update && apt-get install -y --allow-unauthenticated pmm-client; \
apt-get remove --purge --force-yes -y apt-transport-https; \
apt-get autoremove -y --force-yes --purge; \
rm -rf /var/lib/apt/lists/* \
true
COPY initpmm.sh /root/
说明:
主要是initpmm.sh 文件,进行exporter metrics 注册
#!/bin/sh
while ! pmm-admin config --client-name mysql1 --server pmmserver
do
sleep 1
done
pmm-admin add external:metrics mysql-demo mysqlexporter:9104
启动&&配置
- 启动
docker-compose up -d
- 注册mysql 以及pg metrics
docker-compose exec mysql sh /root/initpmm.sh
OK, PMM server is alive.
PMM Server | pmmserver
Client Name | mysql1
Client Address | 172.24.0.8
External metrics added.
docker-compose exec postgres sh /root/initpmm.sh
OK, PMM server is alive.
PMM Server | pmmserver
Client Name | pg1
Client Address | 172.24.0.6
External metrics added.
- prometheus target 效果
- grafana 效果
- 配置gogs导入部分数据
- pg 导入数据
docker-compose up pgloader-mysql
效果
pgloader-mysql_1 | WARNING:
pgloader-mysql_1 | Couldn't re-execute SBCL with proper personality flags (/proc isn't mounted? setuid?)
pgloader-mysql_1 | Trying to continue anyway.
pgloader-mysql_1 | 2019-08-05T14:26:59.075000Z LOG pgloader version "3.6.2~devel"
pgloader-mysql_1 | 2019-08-05T14:26:59.212000Z LOG Migrating from #<MYSQL-CONNECTION mysql://root@mysql:3306/gogs {1006496943}>
pgloader-mysql_1 | 2019-08-05T14:26:59.213000Z LOG Migrating into #<PGSQL-CONNECTION pgsql://postgres@postgres:5432/appdemo {10066DF6D3}>
pgloader-mysql_1 | 2019-08-05T14:27:01.364000Z LOG report summary reset
pgloader-mysql_1 | table name errors rows bytes total time
pgloader-mysql_1 | ----------------------------- --------- --------- --------- --------------
pgloader-mysql_1 | fetch meta data 0 119 0.256s
pgloader-mysql_1 | Create Schemas 0 0 0.013s
pgloader-mysql_1 | Create SQL Types 0 0 0.027s
pgloader-mysql_1 | Create tables 0 72 0.411s
pgloader-mysql_1 | Set Table OIDs 0 36 0.004s
pgloader-mysql_1 | ----------------------------- --------- --------- --------- --------------
pgloader-mysql_1 | gogs.access 0 0 0.032s
pgloader-mysql_1 | gogs.access_token 0 0 0.021s
pgloader-mysql_1 | gogs.action 0 0 0.078s
pgloader-mysql_1 | gogs.attachment 0 0 0.113s
pgloader-mysql_1 | gogs.collaboration 0 0 0.030s
pgloader-mysql_1 | gogs.deploy_key 0 0 0.068s
pgloader-mysql_1 | gogs.comment 0 0 0.122s
pgloader-mysql_1 | gogs.follow 0 0 0.075s
pgloader-mysql_1 | gogs.issue 0 0 0.102s
pgloader-mysql_1 | gogs.email_address 0 0 0.142s
pgloader-mysql_1 | gogs.hook_task 0 0 0.157s
pgloader-mysql_1 | gogs.issue_user 0 0 0.114s
pgloader-mysql_1 | gogs.issue_label 0 0 0.135s
pgloader-mysql_1 | gogs.login_source 0 0 0.130s
pgloader-mysql_1 | gogs.label 0 0 0.154s
pgloader-mysql_1 | gogs.mirror 0 0 0.154s
pgloader-mysql_1 | gogs.milestone 0 0 0.139s
pgloader-mysql_1 | gogs.org_user 0 0 0.122s
pgloader-mysql_1 | gogs.notice 0 0 0.154s
pgloader-mysql_1 | gogs.protect_branch 0 0 0.128s
pgloader-mysql_1 | gogs.protect_branch_whitelist 0 0 0.134s
pgloader-mysql_1 | gogs.public_key 0 0 0.141s
pgloader-mysql_1 | gogs.pull_request 0 0 0.147s
pgloader-mysql_1 | gogs.release 0 0 0.170s
pgloader-mysql_1 | gogs.repository 0 0 0.143s
pgloader-mysql_1 | gogs.star 0 0 0.146s
pgloader-mysql_1 | gogs.team 0 0 0.149s
pgloader-mysql_1 | gogs.team_user 0 0 0.149s
pgloader-mysql_1 | gogs.team_repo 0 0 0.166s
pgloader-mysql_1 | gogs.two_factor_recovery_code 0 0 0.151s
pgloader-mysql_1 | gogs.two_factor 0 0 0.155s
pgloader-mysql_1 | gogs."user" 0 1 0.3 kB 0.167s
pgloader-mysql_1 | gogs.upload 0 0 0.178s
pgloader-mysql_1 | gogs.watch 0 0 0.162s
pgloader-mysql_1 | gogs.version 0 1 0.0 kB 0.179s
pgloader-mysql_1 | gogs.webhook 0 0 0.167s
pgloader-mysql_1 | ----------------------------- --------- --------- --------- --------------
pgloader-mysql_1 | COPY Threads Completion 0 4 0.316s
pgloader-mysql_1 | Create Indexes 0 83 0.644s
pgloader-mysql_1 | Index Build Completion 0 83 0.222s
pgloader-mysql_1 | Reset Sequences 0 36 0.026s
pgloader-mysql_1 | Primary Keys 0 36 0.049s
pgloader-mysql_1 | Create Foreign Keys 0 0 0.000s
pgloader-mysql_1 | Create Triggers 0 0 0.001s
pgloader-mysql_1 | Set Search Path 0 1 0.002s
pgloader-mysql_1 | Install Comments 0 0 0.000s
pgloader-mysql_1 | ----------------------------- --------- --------- --------- --------------
pgloader-mysql_1 | Total import time ? 2 0.3 kB 1.260s
pmm-docker_pgloader-mysql_1 exited with code 0
- mysql 指标信息查看
- pg 指标查看
- 另外一种添加数据库以及metrics 的方法
实际上pmm也提供了通过界面添加的方法,如下图
添加mysql
- 查询分析界面
说明
pmm 提供的指标模版还是很全的,包含了我们实际数据库分析中的很多方便的指标,可以帮助我们方便的分析系统的瓶颈,同时官方文档
也比较全的提供了操作手册(有pdf版本的)
参考资料
https://www.percona.com/doc/percona-monitoring-and-management/index.html
https://github.com/rongfengliang/pmm-learning