从零搭建MySQL监控平台(mysql-exporter+Prometheus+Grafana)


本文是我自己在Macbook上本地从零开始搭建一套MySQL监控平台,监控的也是我本机的MySQL,过程包括prometheus、mysql_exporter、Grafana的配置与下载。

一、软件安装

我是根据Mac挑选的如下版本下载:

OSArch
darwinamd64

prometheus: 普罗米修斯是一个监控工具,以时间为单位展示指定数据维度的变化趋势。
Download | Prometheus->prometheus->prometheus-2.43.0.darwin-amd64.tar.gz

mysql_exporter:mysql数据采集器
Download | Prometheus->mysqld_exporter->mysqld_exporter-0.15.0-rc.0.darwin-amd64.tar.gz

Grafana:可视化展示的监控软件,支持多种仪表盘
Download Grafana | Grafana Labs-> Mac

二、 软件配置

配置mysql_exporter

  1. 进入上面mysqld_exporter-0.15.0-rc.0.darwin-amd64解压的目录中,touch my.cnf创建配置文件

  2. 进行my.cnf文件配置

    输入想要采集数据的登陆用户信息,即本地数据库信息

    [client] 
    # mysql用户名 
    user=xxxxx  
     
    #mysql的密码
    password=xxxxx
     
    #主机地址
    host=localhost
     
    # mysql端口号
    prot=3306
    
  3. 启动mysql-exporter

    ./mysqld_exporter --config.my-cnf=./my.cnf
    
  4. 本地浏览器访问端口9104监控页面

    http://localhost:9104/
    

    显示如下,则成功,但是这亮橙色,真的很容易让人认为报错了orz:

在这里插入图片描述

点进去Metrics就能看到具体的采集到的信息

配置prometheus

  1. 进入上面mysqld_exporter-0.15.0-rc.0.darwin-amd64解压的目录中

  2. 配置prometheus.yml文件中的scrape_configs

    以相同的格式,添加mysql的监听任务以及其监听端口9104:

    - job_name: "mysql"
    
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.
    
        static_configs:
          - targets: ["localhost:9104"]
    

    最终如下:

    # my global config
    global:
      scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
      evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
      # scrape_timeout is set to the global default (10s).
    
    # Alertmanager configuration
    alerting:
      alertmanagers:
        - static_configs:
            - targets:
              # - alertmanager:9093
    
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
    
    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
      # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
      - job_name: "prometheus"
    
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.
    
        static_configs:
          - targets: ["localhost:9090"]
    
      - job_name: "mysql"
    
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.
    
        static_configs:
          - targets: ["localhost:9104"]
    
  3. 启动prometheus

    ./prometheus
    
  4. 本地浏览器访问端口9090监控页面

    http://localhost:9090/
    
  5. 进入Status-Targets查看上面收集的Metrics指标

在这里插入图片描述

配置Grafana

  1. 进入解压后的目录grafana-9.4.7/bin

  2. 运行grafana

    ./grafana-server
    
  3. 本地浏览器访问端口3000监控页面

    http://localhost:3000/
    
  4. 添加prometheus数据源
    在这里插入图片描述

    设置prometheus URL地址并Save&Test:
    在这里插入图片描述

  5. Dashboards导入仪表盘
    Dashboards–>Import

填入模板链接:https://grafana.com/grafana/dashboards/7362-mysql-overview
在这里插入图片描述
在这里插入图片描述

  1. 结果展示如下
    在这里插入图片描述
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

互联网民工蒋大钊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值