Advertisement

PMM(Percona Monitoring and Management)监控MySQL数据库

阅读量:

前言

  • Percona Monitoring and Management (PMM) 是一款开源工具, 专门用于维护 MySQL、MongoDB、PostgreSQL、ProxySQL 和 AWS RDS 的性能, 并且能够监控这些数据库服务器上的资源情况. 利用 PMM 客户端收集到的数据, 可以借助第三方软件 Grafana 进行可视化展示.
  • 通过 PMM, 可以获得以下信息

1、全面的多维度的系统运行状态展示
2、由复杂多系统的拓扑关系数据驱动的状态评估
3、深入解析效率低下原因的同时主动识别潜在性能问题并提供解决方案
4、排查潜在风险并采取措施应对

PMM简介

PMM Server架构

PMM Server
  • Query Analytics (QAN) 支持在指定时间段内测定MySQL查询性能,并不仅仅局限于客户端QAN代理功能,它还涵盖了其他相关功能。

  • QAN API专指用于存储、获取及管理由PMM客户端上的QAN代理所收集的查询数据的后台服务器系统。

  • QAN Web App应用程序特指一种用于展示和管理收集到的查询分析数据的Web类型应用程序。

  • Metrics Monitor 提供对MySQL或MongoDB Server实例至关重要的历史视图,并包含以下内容:

  • VictoriaMetrics, 一种基于时序型数据库的技术.
    (从前文中的PMM 2.12.0中使用Prometheus替代得出)

  • ClickHouse 是一种支持列式存储技术的第三方数据库,提供了方便查询分析功能.

  • Grafana 是一个基于Go语言开发的开源数据可视化平台,支持数据监控与统计分析,并具备告警功能.

  • Percona Dashboards 是我们开发的一个基于Grafana的数据仪表板集合。

PMM Client架构

PMM Client

pmm-admin 是专门用于管理PMM客户端的命令行工具,在文档中可以看到具体的操作方法(例如增添和删除要监视的数据库实例)。(Read more.)

pmm-agent 是一种客户端组件;它是连接到客户端功能的主要入口点;这种工具集整合了基本的功能模块;其中包含了客户身份认证系统;能够从PMM服务器上获取相关的配置信息;并负责管理性能数据收集器以及其他代理服务

node_exporter 服务器性能数据收集器.

mysqld_exporter MySQL性能数据收集器.

mongodb_exporter MongoDB性能数据收集器.

postgres_exporter PostgreSQL性能数据收集器.

proxysql_exporter ProxySQL 性能数据收集器.

rds_exporter Amazon RDS性能数据收集器.

azure_database_exporter Azure database性能数据收集器.

安装部署

PMM Server

  • 创建docker-compose_prometheus_grafana.yml配置文件
复制代码
    cd /opt/docker-compose
    touch docker-compose_pmm-server.yml
    
    
    shell
  • 编辑docker-compose_pmm-server.yml文件并键入
复制代码
    services:
      pmm-server:
    image: percona/pmm-server:2
    hostname: pmm-server
    container_name: pmm-server
    restart: always
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "5"
    ports:
      - "443:443"
    volumes:
      - data:/srv
    volumes:
      data:
    
    
    yaml
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-13/P0fgHTG7w1RuCEjnvlmirsy2hcNb.png)

With this approach, data is stored in a volume, not in a pmm-data container.

  • 查看数据卷
复制代码
    docker volume ls
    
    local               pmm-server_data
    
    
    shell
  • 如果存在垃圾数据,可以尝试以下命令进行清除
复制代码
    docker stop pmm-server
    
    docker rm pmm-server
    
    
    shell
复制代码
    docker inspect pmm-server_data
    [
    {
        "CreatedAt": "2021-05-28T16:16:15+08:00",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "pmm-server",
            "com.docker.compose.version": "1.29.2",
            "com.docker.compose.volume": "data"
        },
        "Mountpoint": "/var/lib/docker/volumes/pmm-server_data/_data",
        "Name": "pmm-server_data",
        "Options": null,
        "Scope": "local"
    }
    ]
    
    
    shell
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-13/wJutLIOV0oKcjH5zhR2AkPy8Ex47.png)
复制代码
    docker volume rm -f pmm-server_data
    
    
    shell
  • 或者使用以下方式将数据存储在 pmm-data container内
复制代码
    version: '2'
    # version 2 of docker-compose is not "old" version, it's the actual version,
    # see below for explanation:
    # https://stackoverflow.com/a/53636006/961092
    services:
    # Percona Monitoring and Management server
    pmm-data:
        image: percona/pmm-server:2
        container_name: pmm-data
        hostname: pmm-data
        volumes:
            - /srv
        entrypoint: /bin/true
    
    pmm-server:
        image: percona/pmm-server:2
        hostname: pmm-server
        container_name: pmm-server
        restart: always
    
    
        # logging settings limit used disk space
        logging:
            driver: json-file
            options:
                max-size: "10m"
                max-file: "5"
    
        ports:
            - "443:443"
        # uncomment expose section in order to proxy requests through another container instead of
        # accessing the container directly
        # expose:
        #     - "443"
    
        volumes_from:
            - pmm-data
    
    
    dockerfile
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-13/yvdYbm0N1HSlV7texAq2n9LkCDZO.png)
  • docker-composedocker容器
复制代码
    docker-compose -p pmm-server -f docker-compose_pmm-server.yml up -d
    
    
    docker
复制代码
    docker volume ls
    DRIVER              VOLUME NAME
    local               f9ed9b5237aecec9ee6c3afce336161582d4d5f79e3dbcc09dca80d78c18ac22

通过以下命令访问pmm-server命令查看pmm-server状态信息

复制代码
    docker exec pmm-server pmm-admin status
    
    
    shell
  • 成功后会出现以下信息
复制代码
    Agent ID: pmm-server
    Node ID : pmm-server
    
    PMM Server:
        URL    : https://127.0.0.1:443/
        Version: 2.17.0
    
    PMM Client:
        Connected        : true
        Time drift       : 56.117µs
        Latency          : 428.232µs
        pmm-admin version: 2.17.0
        pmm-agent version: 2.17.0
    Agents:
        /agent_id/6a7e8dcb-8aa8-4b65-8447-ff8284904348 postgresql_pgstatements_agent Running
        /agent_id/92688359-7668-47f5-9a93-eaf46ba9cf22 node_exporter Running
        /agent_id/a223620e-7a16-43ee-bf63-bd1dbe33ba01 postgres_exporter Running
    
    
    
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-13/QiuHxAXtZmaVjBJrb5T6N93Mcyg7.png)
  • 启动成功通过浏览器443端口访问pmm-server服务
pmm-server
  • 修改admin密码为pmm-reporter

PMM Client

  • 创建docker-compose.yml配置文件
复制代码
    cd /opt/docker-compose/pmm-client
    touch docker-compose.yml
    
    
    shell

请配置 docker-compose.yml 文件并输入以下命令:Assign unique hostnames to each PMM client.

复制代码
    version: '2'
    services:
      pmm-client:
    image: percona/pmm-client:2
    hostname: pmm-client-myhost
    container_name: pmm-client
    restart: always
    ports:
      - "42000:42000"
      - "42001:42001"
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "5"
    volumes:
      - ./pmm-agent.yaml:/etc/pmm-agent.yaml
      - pmm-client-data:/srv
    environment:
      - PMM_AGENT_CONFIG_FILE=/etc/pmm-agent.yaml
     entrypoint: pmm-agent setup --server-insecure-tls --server-address=192.168.9.140:443 --server-username=admin --server-password=pmm-reporter
    volumes:
      pmm-client-data:
    
    
    yaml
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-13/P43IRx0NsBLlTyObXCUrzj8hcnZV.png)
  • 生成配置文件
复制代码
    cd /opt/docker-compose/pmm-client
    touch pmm-agent.yaml && chmod 0666 pmm-agent.yaml
    
    with mode 0666 so container user will be able to write to it
    
    
    shell
  • 使用以下命令启动后会立即停下,并自动映射当前目录下pmm-agent.yaml
复制代码
    docker-compose up pmm-client
    
    
    shell
复制代码
    Creating volume "pmm-client_pmm-client-data" with default driver
    Creating pmm-client ... done
    Attaching to pmm-client
    pmm-client    | INFO[2021-05-28T11:51:35.526+00:00] Loading configuration file /etc/pmm-agent.yaml.  component=setup
    pmm-client    | INFO[2021-05-28T11:51:35.542+00:00] Using /usr/local/percona/pmm2/exporters/node_exporter  component=setup
    pmm-client    | INFO[2021-05-28T11:51:35.542+00:00] Using /usr/local/percona/pmm2/exporters/mysqld_exporter  component=setup
    pmm-client    | INFO[2021-05-28T11:51:35.542+00:00] Using /usr/local/percona/pmm2/exporters/mongodb_exporter  component=setup
    pmm-client    | INFO[2021-05-28T11:51:35.542+00:00] Using /usr/local/percona/pmm2/exporters/postgres_exporter  component=setup
    pmm-client    | INFO[2021-05-28T11:51:35.542+00:00] Using /usr/local/percona/pmm2/exporters/proxysql_exporter  component=setup
    pmm-client    | INFO[2021-05-28T11:51:35.542+00:00] Using /usr/local/percona/pmm2/exporters/rds_exporter  component=setup
    pmm-client    | INFO[2021-05-28T11:51:35.542+00:00] Using /usr/local/percona/pmm2/exporters/azure_exporter  component=setup
    pmm-client    | INFO[2021-05-28T11:51:35.542+00:00] Using /usr/local/percona/pmm2/exporters/vmagent  component=setup
    pmm-client    | Checking local pmm-agent status...
    pmm-client    | pmm-agent is not running.
    pmm-client    | Registering pmm-agent on PMM Server...
    pmm-client    | Registered.
    pmm-client    | Configuration file /etc/pmm-agent.yaml updated.
    pmm-client    | Please start pmm-agent: `pmm-agent --config-file=/etc/pmm-agent.yaml`.
    
    
    shell
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-13/ko0fCRFALzqe3GNDbP9HJQnyvXmh.png)

查看pmm-agent.yml配置信息

复制代码
    # Updated by `pmm-agent setup`.
    ---
    id: /agent_id/0c514bcf-41ac-4de8-9d2c-57cb4b8523bf
    listen-address: 127.0.0.1
    listen-port: 7777
    server:
    address: 192.168.9.1xx:443
    username: admin
    password: pmm-reporter
    insecure-tls: true
    paths:
    exporters_base: /usr/local/percona/pmm2/exporters
    node_exporter: /usr/local/percona/pmm2/exporters/node_exporter
    mysqld_exporter: /usr/local/percona/pmm2/exporters/mysqld_exporter
    mongodb_exporter: /usr/local/percona/pmm2/exporters/mongodb_exporter
    postgres_exporter: /usr/local/percona/pmm2/exporters/postgres_exporter
    proxysql_exporter: /usr/local/percona/pmm2/exporters/proxysql_exporter
    rds_exporter: /usr/local/percona/pmm2/exporters/rds_exporter
    azure_exporter: /usr/local/percona/pmm2/exporters/azure_exporter
    vmagent: /usr/local/percona/pmm2/exporters/vmagent
    tempdir: /tmp
    pt_summary: /usr/local/percona/pmm2/tools/pt-summary
    pt_pg_summary: /usr/local/percona/pmm2/tools/pt-pg-summary
    pt_mysql_summary: /usr/local/percona/pmm2/tools/pt-mysql-summary
    pt_mongodb_summary: /usr/local/percona/pmm2/tools/pt-mongodb-summary
    ports:
    min: 42000
    max: 51999
    debug: false
    trace: false
    
    
    shell
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-13/mjfxA9OYc0unv6lh3eG82Fz54KNr.png)
  • docker-compose.yml配置文件entrypoint信息注释掉,如下
复制代码
    #     entrypoint: pmm-agent setup --server-insecure-tls --server-address=192.168.9.140:443 --server-username=admin --server-password=pmm-reporter
    
    
    yaml
  • docker-composedocker容器
复制代码
    docker-compose -p pmm-client -f docker-compose.yml up -d
    Recreating pmm-client ... done
    
    
    shell
  • 通过以下命令访问pmm-client命令查看pmm-client状态信息
复制代码
    docker exec pmm-client pmm-admin status
    
    
    shell
  • 成功后会出现以下信息
复制代码
    Agent ID: /agent_id/0c514bcf-41ac-4de8-9d2c-57cb4b8523bf
    Node ID : /node_id/8d7cb9d5-c407-4c87-ba0f-ee28e68d2725
    
    PMM Server:
        URL    : https://192.168.9.140:443/
        Version: 2.17.0
    
    PMM Client:
        Connected        : true
        Time drift       : 81.61µs
        Latency          : 585.095µs
        pmm-admin version: 2.16.0-release-2.16-ebcf4316
        pmm-agent version: 2.16.0-release-2.16-ebcf4316
    Agents:
        /agent_id/50269d19-7663-4650-8c66-48356ce2ccde vmagent Running
        /agent_id/5a86413f-0c1b-4312-aac0-99f6f1a07ecc node_exporter Running
    
    
    shell
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-07-13/nGDR4Av2w0W7cHuCgUTl9omBeIdk.png)
  • 服务启动成功后会自动注册node节点
复制代码
    docker exec pmm-client pmm-admin list
复制代码
    Service type   Service name   Address and port  Service ID
    Agent type     Status         Metrics Mode      Agent ID                                       Service ID
    pmm_agent      Connected                        /agent_id/0c514bcf-41ac-4de8-9d2c-57cb4b8523bf 
    node_exporter  Running        push              /agent_id/5a86413f-0c1b-4312-aac0-99f6f1a07ecc 
    vmagent        Running        push              /agent_id/50269d19-7663-4650-8c66-48356ce2ccde
    
    
    shell
  • 如图所示
Home-Dashboard

共同运行于同一台服务器上的pmm-server与pmm-client当前仍未配置数据库服务

pmm-client-myhost

注册Client

当pmm-client与pmm-server服务在同一台机器上,pmm-client服务启动成功后,会自动执行注册Client。

如果非同一台机器,则需要手动执行注册Client。

  • 向pmm-server注册pmm-client节点
复制代码
    docker exec pmm-client pmm-admin config --server-insecure-tls --server-url=https://admin:pmm-exporter@192.168.9.1xx:443 192.168.9.1xx generic pmm-client-myhost
    
    
    shell
  • 注册成功提示以下信息
复制代码
    Checking local pmm-agent status...
    pmm-agent is running.
    Registering pmm-agent on PMM Server...
    Registered.
    Configuration file /etc/pmm-agent.yaml updated.
    Reloading pmm-agent configuration...
    Configuration reloaded.
    Checking local pmm-agent status...
    pmm-agent is running.
    
    
    shell

监控数据库

  • 首次使用先检查一下,确认是没有mysql类型的service
复制代码
    docker exec pmm-client pmm-admin inventory list services --service-type=mysql
    
    
    shell
复制代码
    Services list.
    
    Service type           Service name         Address and Port  Service ID
    
    
    shell
  • 创建并授权数据库用户
复制代码
    CREATE USER 'pmm'@'localhost' IDENTIFIED BY 'pmm-client' WITH MAX_USER_CONNECTIONS 10;
    GRANT SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD ON *.* TO 'pmm'@'localhost';
    FLUSH PRIVILEGES;
    
    
    sql
  • 确保mysql数据库中PERFORMANCE_SCHEMA参数值处于开启状态

自MySQL 5.5起新增一个数据库:PERFORMANCE_SCHEMA,默认于5.5版本禁用并于5.6版本启用。

复制代码
    root@localhost 14:43:  [(none)]>SHOW VARIABLES LIKE 'performance_schema';
    +--------------------+-------+
|Variable_name|Value|

    +--------------------+-------+
|performance_schema|ON|

    +--------------------+-------+
    1 row in set (0.00 sec)
    
    
    sql

Data source recommendations

Database server Versions Recommended source
MySQL 5.1-5.5 Slow query log
MySQL 5.6+ Performance Schema
MariaDB 10.0+ Performance Schema
Percona Server for MySQL 5.7, 8.0 Slow query log
Percona XtraDB Cluster 5.6, 5.7, 8.0 Slow query log

将pmm-client节点中的mysql数据库service添加至pmm-server

复制代码
    docker exec pmm-client pmm-admin add mysql --query-source=perfschema --username=pmm --password=pmm-client pmm-client-myhost 192.168.9.1xx:3306
    
    
    shell
复制代码
    MySQL Service added.
    Service ID  : /service_id/5baab9a7-1e3a-441e-8d9e-27ff7b5b5da8
    Service name: pmm-client-myhost
    
    Table statistics collection enabled (the limit is 1000, the actual table count is 476).
    
    
    shell
  • 浏览器页面开始展示mysql相关信息
mysql
  • 再次查询已经存在mysql类型的service
复制代码
    docker exec pmm-client pmm-admin inventory list services --service-type=mysql
    Services list.
    
    Service type    Service name         Address and Port  Service ID
    MySQL           pmm-client-myhost    192.168.9.1xx:3306 /service_id/5baab9a7-1e3a-441e-8d9e-27ff7b5b5da8
  • 当然也可以移除数据库services
复制代码
    docker exec pmm-client pmm-admin remove <service-type> <service-name>
    
    <service-type>:mysql,mongodb,postgresql,proxysql,haproxy,external
    
    docker exec pmm-client pmm-admin remove mysql pmm-client-myhost
    
    
    shell

具体使用

  • Nodes OverView概览信息展示
Nodes OverView
  • Nodes分类详细信息
Nodes分类详细信息
  • MySQL Instances Overview概览信息
MySQL Instances Overview
  • MySQL Performance Schema Details
MySQL Performance Schema Details

参考文档

https://www.percona.com/software/pmm/quickstart

The document discusses the architecture of Percona Monitoring and Management System, providing detailed insights into its design and implementation. It delves into the overall system structure, highlighting key components such as the database engine, storage management, and replication mechanisms. The text also explores how these elements contribute to the system's scalability and reliability, emphasizing best practices for optimization and maintenance. This resource is essential for developers and administrators seeking to understand and implement effective monitoring strategies in their environments.

此文档详细阐述了如何为Percona Monitoring and Management系统设置服务器环境。该指南的主要步骤包括启动网络监控功能、配置服务器参数以及设定警报与通知机制。通过访问以下URL(请参考链接中的信息),您可以在浏览器中直接访问此文档。如需更多详细信息,请参考完整的文档资源(请访问上述链接获取)。如您有任何问题或需要进一步的帮助,请联系支持团队(邮箱地址见上文)。

https://www.percona.com/doc/percona-monitoring-and-management/2.x/setting-up/client/index.html

The article provides detailed instructions on how to register a client for Percona Monitor and Management. It explains the process of configuring the client application and installing it on the target system, ensuring seamless integration with the monitoring tools.

https://www.percona.com/doc/percona-monitoring-and-management/2.x/setting-up/client/mysql.html

此链接无法进行有效的同义改写以降低重复率

该文档详细指导用户如何配置Percona Monitoring and Management Server(MMMS)以在Docker容器化环境中运行Percona MySQL Cluster(PDC)。具体来说,在Docker容器中初始化MMMS并确保其能够正常连接到PDC集群节点上是实现可靠集群监控与管理的关键前提条件。为了实现这一目标,在构建Docker镜像时必须按照指定的最佳实践进行配置,并且必须遵循MMMS版本兼容性要求以及PDC版本兼容性要求以避免服务中断风险。此外,在完成基本配置后还需要执行一系列验证测试来确认MMMS是否成功初始化以及是否能够正确连接到PDC集群节点上。

https://gist.github.com/paskal/48f10a0a584f4849be6b0889ede9262b

访问该系列文档的HTML索引页面

全部评论 (0)

还没有任何评论哟~