当前位置:   article > 正文

手把手教你Prometheus + Granafa实现mysql 性能监测部署_mysql 性能推送granfana

mysql 性能推送granfana

        一、前言
         二、部署过程与问题记录
         1.prometheus下载与启动
         2.mysqld_exporter下载与启动
         3.grafana下载与启动
         4.运行Prometheus + Granafa步骤总结

一、前言

    数据库性能监控可以说是十分重要,能否自行搭建环境实现像阿里云或是腾讯云那样直观的展示不同维度数据的功能?答案是肯定的。下面详细说明一下安装部署过程以及过程中出现的问题,希望对你有所帮助!

二、部署过程与问题记录

    首先介绍一下用到的三个开源程序:
    prometheus:普罗米修斯可以简单理解为一个监控工具,以时间为单位展示指定数据维度的变化趋势。数据信息从哪来?主要是依赖数据采集器,对于mysql数据采集使用的是mysqld_exporter
    grafana:主要用于可视化展示的监控软件,让数据监控更直观,支持多种仪表盘类型,就好比经常见的数据大屏,仪表盘就是各种展示形式。下面分别讲下三个如何下载和安装。

1.prometheus下载与启动

    官方下载地址:
https://prometheus.io/download/
    本文主要讲解如何在windows上安装,所以选择windows版本,这里下载版本为:prometheus-2.40.1.windows-amd64.zip
解压之后找到prometheus.exe直接进行双击即可启动。
看到下面的内容说明启动成功:
在这里插入图片描述

查看启动端口:
在这里插入图片描述
浏览器中直接访问:localhost:9090
在这里插入图片描述

2.mysqld_exporter下载与启动

    官方下载地址同上:https://prometheus.io/download/,这里下载的版本为:
mysqld_exporter-0.14.0.windows-amd64.zip.解压之后需要添加my.cnf文件(注意:解压完成之后是不存在这个文件的,需要手动添加)。主要作用是配置数据库连接信息。my.cnf中添加内容如下:

[client]  
user=root  
password=****
host=192.125.256.12
prot=3308
  • 1
  • 2
  • 3
  • 4
  • 5

启动方式:mysqld_exporter解压所在目录中执行(注意不是双击mysqld_exporter.exe启动):

mysqld_exporter.exe --config.my-cnf=my.cnf
  • 1

在这里插入图片描述
访问地址:localhost:9104
收集的mysql信息如下:
在这里插入图片描述
prometheus中配置mysqld_exporter,两者进行关联,从prometheus.yml中最后位置添加mysqld_exporterprometheus.yml源文件内容如下:

# 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"]
   # 自定义添加mysql监控任务 
   - job_name: "mysql_monitor"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

添加mysqld_exporter之后:

# 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"]
   # 自定义添加mysql监控任务 
   - job_name: "mysql_monitor"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

	# 监控mysql采集器
    static_configs:
      - targets: ["localhost:9104"]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

配置好之后重启prometheus,将prometheus.exe运行窗口关闭,双击prometheus.exe即可。mysqld_exporter重启方式同理。访问localhost:9090,选择targets,正常情况下应该是有两条任务。
在这里插入图片描述
在这里插入图片描述

说下遇到的两个问题:
    关闭prometheus.exe然后重新启动出现闪退。
    出现这种情况一般是yml格式缩进问题,新增内容和原始文件的缩进保持一致即可.
    访问localhost:8090,右边error中显示Get "http://localhost:9104/metrics": dial tcp: lookup localhost on 114.114.114.114:53: no such host
    处理方式:将prometheus.yml中localhost修改为本机ip,也不要使用127.0.0.1.

3.grafana下载与启动

    下载地址:https://grafana.com/grafana/download,下载完成之后按照步骤安装即可,可以自定义安装目录,此处不做截图说明,安装完成之后访问:localhost:3000.这一步可能会出现问题,直接访问出现下图问题:
在这里插入图片描述
    说下当时的原因:
    本机3000端口被占用,所以访问失败,修改端口为3001。找到defaults.ini并打开,将从下面修改端口号即可。

# The http port to use
http_port = 3000
  • 1
  • 2

    浏览器问题:电脑上安装的谷歌、360浏览器访问都失败,下载了一个狐火浏览器问题解决。当然也试过其他方式比如上面说的重启(找到grafana-server.exe双击)。
在这里插入图片描述

    默认的用户名密码都是admin,登录之后会立即要求修改密码。重新登录之后设置数据源(按照截图步骤进行设置即可):
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

    设置仪表板:

在这里插入图片描述
在这里插入图片描述
输入常用的仪表板格式:https://grafana.com/grafana/dashboards/7362-mysql-overview
在这里插入图片描述

导入成功之后就能监控各种维度信息。
在这里插入图片描述

4.运行Prometheus + Granafa步骤总结

启动普罗修斯米,双击prometheus.exe;
启动mysql数据采集器,cmd进入到mysql数据采集器安装目录执行:

mysqld_exporter.exe --config.my-cnf=my.cnf
  • 1

访问Granafa,浏览器访问:http://localhost:3001
    至此mysql数据监控环境搭建完成!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/307383
推荐阅读
相关标签
  

闽ICP备14008679号