ElasticSearch之Slow Log
ElasticSearch
的慢日志,相关的参数及配置方法。
在log4j2.properties
中配置慢日志的输出文件名。
Search Slow Log
相关参数
index.search.slowlog.threshold.query.warn
index.search.slowlog.threshold.query.info
index.search.slowlog.threshold.query.debug
index.search.slowlog.threshold.query.trace
index.search.slowlog.threshold.fetch.warn
index.search.slowlog.threshold.fetch.info
index.search.slowlog.threshold.fetch.debug
index.search.slowlog.threshold.fetch.trace
上述参数的默认值均为-1
,即关闭日志的输出。
参数值为时长,单位如下:
s
,即秒,样例:10s
。ms
,即毫秒,样例:10ms
。
修改各参数的时长,命令样例,如下:
curl -X PUT "https://localhost:9200/testindex_001/_settings?pretty" -H 'Content-Type: application/json' -d' { "index.search.slowlog.threshold.query.warn": "10s", "index.search.slowlog.threshold.query.info": "5s", "index.search.slowlog.threshold.query.debug": "2s", "index.search.slowlog.threshold.query.trace": "500ms", "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" } ' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{ "acknowledged" : true }
查看上述参数的当前值,命令样例,如下:
curl -X GET "https://localhost:9200/testindex_001/_settings?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{ "testindex_001" : { "settings" : { "index" : { "routing" : { "allocation" : { "include" : { "_tier_preference" : "data_content" } } }, "search" : { "slowlog" : { "threshold" : { "fetch" : { "warn" : "1s", "trace" : "200ms", "debug" : "500ms", "info" : "800ms" }, "query" : { "warn" : "10s", "trace" : "500ms", "debug" : "2s", "info" : "5s" } } } }, "number_of_shards" : "1", "provided_name" : "testindex_001", "merge" : { "scheduler" : { "max_thread_count" : "2" } }, "creation_date" : "1701354456991", "number_of_replicas" : "1", "uuid" : "7iGJRFfxRd2jD3qP-KDRmQ", "version" : { "created" : "8500003" } } } } }
Index Slow log
相关参数
index.indexing.slowlog.threshold.index.warn
index.indexing.slowlog.threshold.index.info
index.indexing.slowlog.threshold.index.debug
index.indexing.slowlog.threshold.index.trace
上述参数的默认值均为-1
,即关闭日志的输出。
参数值为时长,单位如下:
s
,即秒,样例:10s
。ms
,即毫秒,样例:10ms
。
index.indexing.slowlog.source
,指定在日志中记录数据中_source
时的长度,默认值为1000
。
false
或者0
,记录日志时跳过_source
字段。true
,记录日志时完整记录_source
字段。- 非零值,记录日志时截取
_source
字段的部分。
index.indexing.slowlog.reformat
,输出日志时,对_source
做格式化操作,默认值为true
。
true
,对_source
做格式化操作。false
,不对_source
做格式化操作。
修改各参数的时长,命令样例,如下:
curl -X PUT "https://localhost:9200/testindex_001/_settings?pretty" -H 'Content-Type: application/json' -d' { "index.indexing.slowlog.threshold.index.warn": "10s", "index.indexing.slowlog.threshold.index.info": "5s", "index.indexing.slowlog.threshold.index.debug": "2s", "index.indexing.slowlog.threshold.index.trace": "500ms", "index.indexing.slowlog.source": "1000" } ' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{ "acknowledged" : true }
查看上述参数的当前值,命令样例,如下:
curl -X GET "https://localhost:9200/testindex_001/_settings?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
执行结果的样例,如下:
{ "testindex_001" : { "settings" : { "index" : { "routing" : { "allocation" : { "include" : { "_tier_preference" : "data_content" } } }, "indexing" : { "slowlog" : { "threshold" : { "index" : { "warn" : "10s", "trace" : "500ms", "debug" : "2s", "info" : "5s" } }, "source" : "1000" } }, "number_of_shards" : "1", "provided_name" : "testindex_001", "merge" : { "scheduler" : { "max_thread_count" : "2" } }, "creation_date" : "1701354456991", "number_of_replicas" : "1", "uuid" : "7iGJRFfxRd2jD3qP-KDRmQ", "version" : { "created" : "8500003" } } } } }
控制日志级别
从前述配置方法可以发现,当前慢日志没有提供参数用于控制日志级别。
但可以通过关闭低级别的日志,从而模拟对日志级别的控制。
比如当前只希望记录INFO
级别以上的日志,则可以执行如下日志,关闭debug
和trace
。
curl -X PUT "https://localhost:9200/testindex_001/_settings?pretty" -H 'Content-Type: application/json' -d' { "index.indexing.slowlog.threshold.index.debug": "-1", "index.indexing.slowlog.threshold.index.trace": "-1" } ' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"
相关资料
本文来自博客园,作者:jackieathome,转载请注明原文链接:https://www.cnblogs.com/jackieathome/p/17868772.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南