ES开启慢查询日志

摘要:
10s#超过10秒的查询将生成警告日志index.search.slowlog.threshold.query.info:5s#超过5秒的查询会生成信息日志index.search.slowlog.tthreshold.query.debug:

默认情况,慢日志是不开启的。要开启它,需要定义具体动作(query,fetch 还是 index),你期望的事件记录等级( WARN、INFODEBUG、TRACE 等),以及时间阈值。

es有几种搜索模式,比如 query_then_fetch , 表示先从各个节点query到id,然后整合,再去各个节点拿具体数据

这是一个索引级别的设置,也就是说可以独立应用给单个或所有索引,这个配置是永久的,配置后即使集群重启也会保留

PUT /_all/_settings
{
    "index.search.slowlog.threshold.query.warn":"5s",
    "index.search.slowlog.threshold.query.info":"2s",
    "index.search.slowlog.threshold.query.debug":"1s",
    "index.search.slowlog.threshold.query.trace":"400ms",
    "index.search.slowlog.threshold.fetch.warn":"1s",
    "index.search.slowlog.threshold.fetch.info":"800ms",
    "index.search.slowlog.threshold.fetch.debug":"500ms",
    "index.search.slowlog.threshold.fetch.trace":"200ms",
    "index.indexing.slowlog.threshold.index.warn":"5s",
    "index.indexing.slowlog.threshold.index.info":"2s",
    "index.indexing.slowlog.threshold.index.debug":"1s",
    "index.indexing.slowlog.threshold.index.trace":"400ms"
}

查询慢于 5 秒输出一个 WARN 日志
索引慢于 2 秒输出一个 INFO 日志
获取慢于 1 秒输出一个 DEBUG 日志

参考资料:https://www.elastic.co/guide/cn/elasticsearch/guide/current/logging.html


两种开启方式:

一、通过修改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日志

二、通过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 级别。

免责声明:文章转载自《ES开启慢查询日志》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ubuntu网卡配置TP框架下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

linux文件系统

一、什么是文件系统 操作系统中用于管理和组织磁盘设备上文件的方法和数据结构叫做文件系统. 1.1 根文件系统(rootfs): 在Linux中, 文件系统和倒树形结构一样, 位于最顶层的的一个分区我们称之为根(root), 用于安装linux系统, 类似于Windos的系统盘; 根分区又叫做根文件系统(root filesystem). 根文件系统由内核...

vue 点击展开显示更多 点击收起部分隐藏

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 </head> 7 <style ty...

ios中的UITextField使用大全

– textRectForBounds:    //重写来重置文字区域 – drawTextInRect:    //改变绘文字属性.重写时调用super可以按默认图形属性绘制,若自己完全重写绘制函数,就不用调用super了. – placeholderRectForBounds:  //重写来重置占位符区域 – drawPlaceholderInRect...

SQLyog

下载地址 https://www.cr173.com/soft/689968.html 注册码 Professional 版本: 注册名:luoye2562注册码:ec38d297-0543-4679-b098-4baadf91f983 Enterprise 版本: 注册名:luoye2562注册码: 59adfdfe-bcb0-4762-8267-d7f...

【Swift】iOS开发笔记(二)

前言   这个系列主要是一些开发中遇到的坑记录分享,有助于初学者跨过这些坑,攒够 7 条发一篇。  声明   欢迎转载,但请保留文章原始出处:)   博客园:http://www.cnblogs.com  农民伯伯: http://over140.cnblogs.com 正文   1、用动画更新约束没有动画效果?   缺少 layoutIfNeeded ,...

微信默认表情符号的代码对照表

之前有不少朋友问我,微信公众平台如何发带有表情符号的图片,其实只需要在信息里面插入表情代码就可以使用的。 微信表情对照表如下: 表情图片 字符串代码 替换关键字 /::) 微笑 /::~ 伤心 /::B 美女 /::| 发呆 /:8-) 墨镜 /::< 哭 /::$ 羞 /::X 哑 /::...