赞
踩
一、前言
二、部署过程与问题记录
1.prometheus下载与启动
2.mysqld_exporter下载与启动
3.grafana下载与启动
4.运行Prometheus + Granafa步骤总结
数据库性能监控可以说是十分重要,能否自行搭建环境实现像阿里云或是腾讯云那样直观的展示不同维度数据的功能?答案是肯定的。下面详细说明一下安装部署过程以及过程中出现的问题,希望对你有所帮助!
首先介绍一下用到的三个开源程序:
prometheus
:普罗米修斯可以简单理解为一个监控工具,以时间为单位展示指定数据维度的变化趋势。数据信息从哪来?主要是依赖数据采集器,对于mysql
数据采集使用的是mysqld_exporter
。
grafana:主要用于可视化展示的监控软件,让数据监控更直观,支持多种仪表盘类型,就好比经常见的数据大屏,仪表盘就是各种展示形式。下面分别讲下三个如何下载和安装。
官方下载地址:
https://prometheus.io/download/
本文主要讲解如何在windows上安装,所以选择windows版本,这里下载版本为:prometheus-2.40.1.windows-amd64.zip
解压之后找到prometheus.exe
直接进行双击即可启动。
看到下面的内容说明启动成功:
查看启动端口:
浏览器中直接访问:localhost:9090
官方下载地址同上: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
启动方式:mysqld_exporter
解压所在目录中执行(注意不是双击mysqld_exporter.exe启动):
mysqld_exporter.exe --config.my-cnf=my.cnf
访问地址:localhost:9104
收集的mysql信息如下:
prometheus
中配置mysqld_exporter
,两者进行关联,从prometheus.yml
中最后位置添加mysqld_exporter
。prometheus.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'.
添加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"]
配置好之后重启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.
下载地址:https://grafana.com/grafana/download,下载完成之后按照步骤安装即可,可以自定义安装目录,此处不做截图说明,安装完成之后访问:localhost:3000.这一步可能会出现问题,直接访问出现下图问题:
说下当时的原因:
本机3000端口被占用,所以访问失败,修改端口为3001。找到defaults.ini并打开,将从下面修改端口号即可。
# The http port to use
http_port = 3000
浏览器问题:电脑上安装的谷歌、360浏览器访问都失败,下载了一个狐火浏览器问题解决。当然也试过其他方式比如上面说的重启(找到grafana-server.exe双击)。
默认的用户名密码都是admin,登录之后会立即要求修改密码。重新登录之后设置数据源(按照截图步骤进行设置即可):
设置仪表板:
输入常用的仪表板格式:https://grafana.com/grafana/dashboards/7362-mysql-overview
导入成功之后就能监控各种维度信息。
启动普罗修斯米,双击prometheus.exe;
启动mysql数据采集器,cmd进入到mysql数据采集器安装目录执行:
mysqld_exporter.exe --config.my-cnf=my.cnf
访问Granafa,浏览器访问:http://localhost:3001
至此mysql数据监控环境搭建完成!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。