1. 程式人生 > >Elasticsearch慢查詢日誌配置

Elasticsearch慢查詢日誌配置

參看網址: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 級別。