1. 程式人生 > >es slow query log設置

es slow query log設置

改變 clu 數據 簡單 ref 通過 hold index https

參看網址:https://www.elastic.co/guide/en/elasticsearch/reference/2.3/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 級別。

es slow query log設置