• docker安装mysql exporter并使用grafana+prometheus监控mysql


    在 MySQL 上创建监控用户

    1、进入mysql

    mysql -u用户名 -p密码
    
    • 1

    2、创建用户并赋权

    create user 'exporter'@'%' identified by '123456' with MAX_USER_CONNECTIONS 3 ;
    grant process,replication client,select on *.* to 'exporter'@'%';
    
    • 1
    • 2

    若出现报错

    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
    
    • 1

    先执行命令

    flush privileges
    
    • 1

    方式一:docker部署myql exporter

    docker run -d -p 9104:9104  -e DATA_SOURCE_NAME="exporter:123456@(192.168.12.11:3306)/" --name mysqld_exporter prom/mysqld-exporter
    
    
    • 1
    • 2

    方式二:以linux服务部署

    下载文件

    cd /usr/local/
    wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.0/mysqld_exporter-0.12.0.linux-amd64.tar.gz
    tar xzf mysqld_exporter-0.12.1.linux-amd64.tar.gz
    mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
    
    • 1
    • 2
    • 3
    • 4

    新建组和用户

    赋权

    chown -R prometheus:prometheus /usr/local/mysqld_exporter/mysqld_exporter
    chmod 755 /usr/local/mysqld_exporter/mysqld_exporter
    
    • 1
    • 2

    配置

    vim /usr/local/mysqld_exporter/.my.cnf
    [client]
    host=127.0.0.1
    port=3306
    user=exporter
    password=123456
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    vim /usr/lib/systemd/system/mysqld_exporter.service
    [Unit]
    Description=mysqld_exporter
    Documentation=https://prometheus.io/
    After=network.target
    
    [Service]
    Type=simple
    User=prometheus
    ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --web.listen-address=0.0.0.0:9104 --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf \
    --log.level=error \
    --collect.info_schema.processlist \
    --collect.info_schema.innodb_metrics \
    --collect.info_schema.innodb_tablespaces \
    --collect.info_schema.innodb_cmp \
    --collect.info_schema.innodb_cmpmem
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    启动

    chown -R prometheus:prometheus /usr/lib/systemd/system/mysqld_exporter.service
    chmod 644 /usr/lib/systemd/system/mysqld_exporter.service
    systemctl daemon-reload
    systemctl enable mysqld_exporter.service
    systemctl start mysqld_exporter.service
    
    • 1
    • 2
    • 3
    • 4
    • 5

    查看启动日志

    journalctl -u mysqld_exporter.service
    
    • 1

    prometheus中添加mysql exporter

    prometheus和grafana部署详见https://blog.csdn.net/u010924720/article/details/125915287

    - job_name: mysql-11.12
        static_configs:
          - targets: ['192.168.12.11:9104']
            labels:
              instance: mysql-11.12
    
    • 1
    • 2
    • 3
    • 4
    • 5

    查看启动命令

    history | grep mysqld_exporter
    
    • 1

    使用grafana监控

    注意:若监控显示no data,重启一下数据库即可
    
    • 1

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 相关阅读:
    【Verilog练习】多路选择器、译码器、半加器、全加器、寄存器(D触发器)、锁存器(Latch)
    ZigBee 3.0实战教程-Silicon Labs EFR32+EmberZnet-2-05:开发板到手测试
    让 GPT-4 来 review 开源社区贡献者的 PR - 每天5分钟玩转 GPT 编程系列(5)
    C++中的extern “C“的作用
    Linux 安装 Gitlab
    python安装mysqldb报错
    GitHubDesktop通过ssh连接Github
    OpenXR手部追踪实现详解
    python pip安装超时使用国内镜像
    【python】python内置函数:print()打印输出信息
  • 原文地址:https://blog.csdn.net/u010924720/article/details/127647834