pmm 添加proxysql metrics

pmm 对于proxysql 的管理是基于metrics的进行处理的,使用的是proxysql exporter
对于proxysql exporter的添加,比较简单,我们可以通过独立的额容器运行exporter 服务

pmm 参考架构

方便大家对于pmm 加深印象

 

环境准备

  • docker-compose文件
    内容比较多,包含了mysql,postgres 的配置,以及exporter
 
version: "3"
services: 
  proxysql-metrics:
    build: 
      context: ./proxysql
      dockerfile: Dockerfile
    image: dalongrong/proxysql-metrics
  proxysql:
    image: proxysql/proxysql:2.0.6
    volumes: 
    - "./proxysql.cnf:/etc/proxysql.cnf"
    - "./db:/var/lib/proxysql"
    ports:
    - "6033:6033"
    - "6032:6032"
  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:
    image: dalongrong/pmm-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:
    image: dalongrong/pmm-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
  • 说明
    对于mysql 以及postgres 的配置以及dockerfile 就不介绍了,可以参考https://www.cnblogs.com/rongfengliang/p/11306210.html
    proxysql-metrics dockerfile 说明,内容比较简单,就是基于debian 集成pmm client ,为了方便运行添加了一个echo 的服务,方便
    容器一直运行,同时进行操作
FROM debian:stretch
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 --fix-missing --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 initpmm.sh /root/
COPY entrypoint.sh /root/
RUN chmod +x /root/entrypoint.sh
ENTRYPOINT [ "/root/entrypoint.sh" ]

entrypoint.sh 容器入口

#!/bin/bash
while true; 
 do echo hello world; 
 sleep 1; 
done

initpmm.sh 配置pmm

#!/bin/sh
while ! pmm-admin config --client-name myproxysql --server pmmserver
do
    sleep 1
done

## 启动&&测试

  • 启动
docker-compose up -d
  • 添加proxysql metrics
配置pmm server
docker-compose exec proxysql-metrics sh /root/initpmm.sh
添加metrics 到pmm
docker-compose exec proxysql-metrics  pmm-admin add proxysql:metrics --dsn "radmin:radmin@tcp(proxysql:6032)/"
  • 效果

prometheus target

 


监控信息

 

说明

以上对于proxysql 的使用很简单,同时使用pmm 可以快速的进行监控,查看系统状态

参考资料

https://github.com/rongfengliang/proxysql-docker-compose
https://github.com/rongfengliang/pmm-learning
https://www.percona.com/doc/percona-monitoring-and-management/index.html

posted on 2019-08-06 17:15  荣锋亮  阅读(749)  评论(0编辑  收藏  举报

导航