kibana 7.5.1 + filebeat 7.5.1实现mysql日志监控

监控流程是通过filebeat从mysql的日志文件中读取信息,上传到elasticsearch中,然后通过kibana进行查询和展示。

1. 下载filebeat

https://www.elastic.co/cn/downloads/past-releases/filebeat-7-5-1

下载filebeat-7.5.1-windows-x86_64.zip后进行解压和配置。

2. 配置filebeat.yml

output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["localhost:9200"]

这里以默认环境进行测试,所以没有需要修改的配置。

3. 初始化mysql日志监控

filebeat.exe modules enable mysql

filebeat.exe modules list

4. 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查看和查询

这里可以查看上传的日志信息,也可以进行查询。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值