监控流程是通过filebeat从mysql的日志文件中读取信息,上传到elasticsearch中,然后通过kibana进行查询和展示。
1. 下载filebeathttps://www.elastic.co/cn/downloads/past-releases/filebeat-7-5-1
下载filebeat-7.5.1-windows-x86_64.zip后进行解压和配置。
2. 配置filebeat.ymloutput.elasticsearch: # Array of hosts to connect to. hosts: ["localhost:9200"]
这里以默认环境进行测试,所以没有需要修改的配置。
3. 初始化mysql日志监控filebeat.exe modules enable mysql filebeat.exe modules list4. mysql的监控配置
modules.d/mysql.yml
- module: mysql
# Error logs
error:
enabled: true
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:
var.paths: ["C:/ProgramData/MySQL/MySQL Server 8.0/Data/mysql.err","C:/ProgramData/MySQL/MySQL Server 8.0/Data/mysql.log"]
# Slow logs
slowlog:
enabled: true
# Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
#var.paths:
var.paths: ["C:/ProgramData/MySQL/MySQL Server 8.0/Data/mysql-slow.log"]
指定mysql的日志文件,支持通配符。
mysql的my.ini中配置的日志文件信息:
# General and Slow logging. log-output=FILE # general-log=0 general-log=1 general_log_file="mysql.log" slow-query-log=1 slow_query_log_file="mysql-slow.log" long_query_time=10 # Binary Logging. log-bin="mysql-bin" # Error Logging. log-error="mysql.err"5. 启动监控
filebeat.exe -e
-e 参数时会输出调试信息。
6. dashboard监控查看在kibana的dashboard找到mysql,可以查看监控信息。
可以看到慢查询日志和错误日志。
7. 通过logs stream查看和查询这里可以查看上传的日志信息,也可以进行查询。



