ES開啓慢查詢日誌

默認狀況,慢日誌是不開啓的。要開啓它,須要定義具體動做(query,fetch 仍是 index),你指望的事件記錄等級( WARN、INFODEBUG、TRACE 等),以及時間閾值。html

es有幾種搜索模式,好比 query_then_fetch , 表示先從各個節點query到id,而後整合,再去各個節點拿具體數據vim

 

這是一個索引級別的設置,也就是說能夠獨立應用給單個或全部索引,這個配置是永久的,配置後即便集羣重啓也會保留elasticsearch

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 日誌ide

 

參考資料:https://www.elastic.co/guide/cn/elasticsearch/guide/current/logging.htmlfetch


兩種開啓方式:

1、經過修改elasticsearch.yml來啓用慢查詢:ui

vim elasticsearch.ymlspa

###Search Slow Log :查詢慢日誌配置,日誌記錄在以「_index_isearch_slowlog.log」  結尾的文件中debug

#注:配置不必定都須要,本身選擇須要那種級別(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日誌code

 

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 級別。

相關文章
相關標籤/搜索