Elasticsearch慢查询日志配置

参看网址:https://www.elastic.co/guide/en/elasticsearch/reference/7.4/index-modules-slowlog.html

1、通过修改elasticsearch.yml来启用慢查询:

vim elasticsearch.yml

###Search Slow Log :查询慢日志配置,日志记录在以“_index_isearch_slowlog.log”  结尾的文件中

#注:配置不一定都需要,自己选择需要那种级别(warn、info、debug、trace)日志,关闭的话配置成-1 就可以了,注释掉重启也可以

index.search.slowlog.threshold.query.warn: 10s  #超过10秒的query产生1个warn日志
index.search.slowlog.threshold.query.info: 5s  #超过5秒的query产生1个info日志
index.search.slowlog.threshold.query.debug: 2s #超过2秒的query产生1个debug日志
index.search.slowlog.threshold.query.trace: 500ms #超过500毫秒的query产生1个trace日志

 

index.search.slowlog.threshold.fetch.warn: 1s  ##fetch阶段的配置
index.search.slowlog.threshold.fetch.info: 800ms
index.search.slowlog.threshold.fetch.debug: 500ms
index.search.slowlog.threshold.fetch.trace: 200ms

 

 

 

###Index Slow log:索引慢日志配置  ,日志记录在以“_index_indexing_slowlog.log”  结尾的文件中

#注:上边四个配置不一定都需要,自己选择需要那种级别(warn、info、debug、trace)日志关闭的话配置成-1就可以了

index.indexing.slowlog.threshold.index.warn: 10s   ##索引数据超过10秒产生一个warn日志
index.indexing.slowlog.threshold.index.info: 5s  ##索引数据超过5秒产生一个info日志
index.indexing.slowlog.threshold.index.debug: 2s ##索引数据超过2秒产生一个ddebug日志
index.indexing.slowlog.threshold.index.trace: 500ms ##索引数据超过500毫秒产生一个trace日志

 

 

2、通过API动态的修改配置:

这是一个索引级别的设置,也就是说可以独立应用给单个索引:这个配置是永久的,配置后即使集群重启也会保留。如果关闭日志记录的话将选项修改成-1即可(例如: "index.search.slowlog.threshold.query.warn" : -1)
 

PUT /my_index/_settings
{
    "index.search.slowlog.threshold.query.warn" : "10s", 
    "index.search.slowlog.threshold.fetch.debug": "500ms", 
    "index.indexing.slowlog.threshold.index.info": "5s" 
}
查询慢于 10 秒输出一个 WARN 日志。
获取慢于 500 毫秒输出一个 DEBUG 日志。
索引慢于 5 秒输出一个 INFO 日志。

 

 



这是一个集群级别的设置:一旦阈值设置过了(可以在 elasticsearch.yml 文件里定义这些阈值。没有阈值设置的索引会自动继承在静态配置文件里配置的参数),你可以和其他日志器一样切换日志记录等级。这个API简单试了下,没效果。并没有改变日志记录级别。而且我没找到集群级别的设置慢查询阈值的API。有知道的发个链接(QQ:1250134974)

 

PUT /_cluster/settings
{
    "transient" : {
        "logger.index.search.slowlog" : "DEBUG", 
        "logger.index.indexing.slowlog" : "WARN" 
    }
}
设置搜索慢日志为 DEBUG 级别。
设置索引慢日志为 WARN 级别。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值