版本信息
- Elasticsearch -7.3.1
- Kibana - 7.3.1
以下是在 Kibana Console 中常用的一些操作
在 Kibana Console 控制台可以操作絕大多數 API,?v - 顯示題頭,?pretty - 格式化輸出,例如:
GET /_cat/indices?v
GET /_cat/thread_pool?pretty
1.調整索引的間隔 - refresh_interval
默認情況下 ElasticSearch 索引的 refresh_interval 為5秒,這意味着數據寫入至少5秒后才可以被搜索到,因此 ElasticSearch 被稱為近實時搜索引擎。
如果需要調整數據刷新方案,則有三種途徑:
(1)設置數據刷新間隔:refresh_interval
(2)調用數據刷新接口:_refresh。
刷新所有 index: POST /_refresh
刷新指定 index: POST /order_logs/_refresh
(3)設置數據刷新策略:RefreshPolicy.
# 調整所有index的刷新間隔為15s PUT { "settings": { "refresh_interval": "15s" } } # 調整指定index的刷新間隔為15秒 PUT /order_logs_2019.12.11 {
"settings": { "refresh_interval": "15s" } }
例如:現在需要將 MySQL 中的數據做一次 Elasticsearch 全量更新,或者初次導入大量數據時,此時可以先關閉自動刷新,全量更新完成之后再打開。
# 關閉全部index的數據刷新 PUT /mysql_logs_2019.12.11 { "settings": { "refresh_interval": -1 } } # 調整指定index的刷新間隔為30秒 PUT /order_logs_2019.12.11 { "settings": { "refresh_interval": "30s"
}
}
2.查看指定索引的 shards 和 replicas 數量
GET /order_logs_2019.12.11/_settings
3.新增一個 ilm policy (索引生命周期管理)模板
indices lifecycle management,此例是從索引建立之后7天,自動刪除索引,ilm policy 可以在索引模板中引用生效
PUT /_ilm/order_logs_ilm_policy {
"policy" : {
"phase" : {
"delete" : {
"min_age" : "7d",
"actions" : {
"delete": {}
}
}
}
}
}
4.新建一個索引模板
{ "index_patterns" : ["order_logs_*"],
"order" : 99, "settings": { "number_of_shares" : 1, "number_of_replicas" : 0, "refresh_interval": "30s",
"index.lifecycle.name" : "odrer_logs_ilm_policy"
},
"mapping" : {
"dynamic" : "false",
"properties" : {
"@timestamp" : {
"type" : "date",
},
"logtime" : {
"type" : "text",
"index" : "true"
},
"level" : {
"type" : "text",
"index" : "true"
},
"component" : {
"type" : "text",
"index" : "true"
},
"threadId" : {
"type" : "text",
"index" : "true"
},
"host.name" : {
"type" : "text",
"index" : "true"
},
"log.file.path" : {
"type" : "text",
"index" : "true"
},
"logbody" : {
"type" : "text",
"index" : "true"
}
}
} }
5.條件篩選
GET /_cat/indices?v&health=yellow
6.結果排序
GET /_cat/indices?v&s=docs.count:desc
7.統計索引的doc行數
統計以 “order_logs_2019.12“ 開頭的索引的 doc 數量
GET /_cat/count/order_logs_2019.12*?v&format=json&pretty
8.查看指定索引的 setting
GET /order_logs_2019.12.11/_settings?pretty
9.擦看各個索引的 shards 配置和空間占用狀態
GET /_cat/shards&s=index:desc
10.查看集群節點屬性
GET /_cat/nodeattrs?v
11.查看jvm
GET /_nodes/stats/jvm
12.查看熱點線程
GET /nodes/hot_threads
13.查看各個線程的狀態,例如寫入線程,查詢線程
6.0之后 bulk 被分拆了,可以通過觀察 elasticsearch 后台日志或是通過使用 thread pool api 來觀察內部線程池的使用情況,以及相應隊列大小,判斷是否還可以繼續調整配置參數。
GET /_node/stats/thread_pool
14.查看集群在忙些啥
正常情況一批 bulk 操作應該是毫秒級的,從 task_id、parent_task_id 可以看出,一個 bulk 操作下面分為寫主分片的動作和寫副本的動作,其中:
indices:data/write/bulk[s][p]:s 表示分片,p 表示主分片。
indices:data/write/bulk[s][r]:s 表示分片,r 表示副本。
GET /_cat/tasks?v
15.查看索引模板
GET /_template/template_order_logs
16.查看 ilm policy (索引生命周期管理)
GET /_ilm/policy
- 其他
監控工具 - Cerebro
監控工具 - Elasticsearch Head