目录
1、索引监控是什么
2、索引的健康状态
3、索引分片的分配
4、索引分片的恢复
5、索引的统计指标
1、索引监控是什么
当你想了解索引运行的状态和统计指标时,需要使用Elasticsearch监控端点。这篇文章将介绍索引的各种监控端点,内容包括监控索引的健康状态,监控索引分片的段数据、分配和恢复,监控索引的统计指标。
2、索引的健康状态
创建一个索引order001,代码如下
PUT order001
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"id":{
"type": "keyword"
}
}
}
}
使用索引的cat端点查看索引order001的健康状态,代码如下
GET _cat/indices/order001?v&format=json
返回结果如下
[
{
"health" : "yellow",
"status" : "open",
"index" : "order001",
"uuid" : "n58cYBLMQiehern0D36c-A",
"pri" : "3",
"rep" : "1",
"docs.count" : "0",
"docs.deleted" : "0",
"store.size" : "624b",
"pri.store.size" : "624b"
}
]
从上面的返回结果中可以查看到索引的健康状态、运行状态、主分片和每个主分片的副本分片的数量、现有文档总数、删除文档总数、索引占用的空间大小、主分片占用的空间大小。由于该索引运行在单节点上,副本分片无法分配,所以主分片占用的空间和索引占用的总空间大小是一样的。索引的健康状态分为3种,如果存在主分片没有得到分配,则健康状态为red;如果存在副本分片没有得到分配,则健康状态为yellow;如果主分片和副本分片都得到了分配,则健康状态为green。你可以在本地启动多个es节点进行验证。
3、索引分片的分配
使用_cat/shards查看索引的每个分片的分配结果,也可以使用_shard_stores端点查看索引中已经分配过的分片所在的位置,不显示未分配的分片所在的位置。
GET order001/_shard_stores
使用这个端点得到的分片存储的信息更加详细,还包括分配id、分片所在节点的详 细信息,具体如下
{
"indices" : {
"order001" : {
"shards" : {
"1" : {
"stores" : [
{
"sby8CsbPRPKoXSyNT9r6Ow" : {
"name" : "365f20b90286",
"ephemeral_id" : "2ij1ohfBRri2o_ezx_bfcg",
"transport_address" : "172.17.0.2:9300",
"attributes" : {
"ml.machine_memory" : "1019383808",
"xpack.installed" : "true",
"transform.node" : "true",
"ml.max_open_jobs" : "20"
}
},
"allocation_id" : "9jdizMerQWaK8u_UHSuL-w",
"allocation" : "primary"
}
]
},
"2" : {
"stores" : [
{
"sby8CsbPRPKoXSyNT9r6Ow" : {
"name" : "365f20b90286",
"ephemeral_id" : "2ij1ohfBRri2o_ezx_bfcg",
"transport_address" : "172.17.0.2:9300",
"attributes" : {
"ml.machine_memory" : "1019383808",
"xpack.installed" : "true",
"transform.node" : "true",
"ml.max_open_jobs" : "20"
}
},
"allocation_id" : "DjFY4N9MQeKo_1MlRHOakg",
"allocation" : "primary"
}
]
},
"0" : {
"stores" : [
{
"sby8CsbPRPKoXSyNT9r6Ow" : {
"name" : "365f20b90286",
"ephemeral_id" : "2ij1ohfBRri2o_ezx_bfcg",
"transport_address" : "172.17.0.2:9300",
"attributes" : {
"ml.machine_memory" : "1019383808",
"xpack.installed" : "true",
"transform.node" : "true",
"ml.max_open_jobs" : "20"
}
},
"allocation_id" : "RypjWGAETP6AiCgkXayzcA",
"allocation" : "primary"
}
]
}
}
}
}
}
4、索引分片的恢复
使用_cat/recovery端点查看分片的恢复情况,使用_recovery端点查看分片恢复的更多细节信息
GET order001/_recovery
在以下的这个端点的返回结果中,除了有分片号(id)、恢复类型(type)、起始时间(start time in millis)、结束时间(stop time in millis)、数据来源(source)和目标节点(target)这些常规的字段之外,还包含分片恢复过程中的统计信息,例如恢复了多少个文件(files.total)、占用多大空间(total in bytes)、恢复的事务日志的个数(translog)等
{
"order001" : {
"shards" : [
{
"id" : 1,
"type" : "EMPTY_STORE",
"stage" : "DONE",
"primary" : true,
"start_time_in_millis" : 1698130829083,
"stop_time_in_millis" : 1698130829216,
"total_time_in_millis" : 133,
"source" : { },
"target" : {
"id" : "sby8CsbPRPKoXSyNT9r6Ow",
"host" : "172.17.0.2",
"transport_address" : "172.17.0.2:9300",
"ip" : "172.17.0.2",
"name" : "365f20b90286"
},
"index" : {
"size" : {
"total_in_bytes" : 0,
"reused_in_bytes" : 0,
"recovered_in_bytes" : 0,
"percent" : "0.0%"
},
"files" : {
"total" : 0,
"reused" : 0,
"recovered" : 0,
"percent" : "0.0%"
},
"total_time_in_millis" : 61,
"source_throttle_time_in_millis" : 0,
"target_throttle_time_in_millis" : 0
},
"translog" : {
"recovered" : 0,
"total" : 0,
"percent" : "100.0%",
"total_on_start" : 0,
"total_time_in_millis" : 49
},
"verify_index" : {
"check_index_time_in_millis" : 0,
"total_time_in_millis" : 0
}
},
{
"id" : 2,
"type" : "EMPTY_STORE",
"stage" : "DONE",
"primary" : true,
"start_time_in_millis" : 1698130829103,
"stop_time_in_millis" : 1698130829216,
"total_time_in_millis" : 113,
"source" : { },
"target" : {
"id" : "sby8CsbPRPKoXSyNT9r6Ow",
"host" : "172.17.0.2",
"transport_address" : "172.17.0.2:9300",
"ip" : "172.17.0.2",
"name" : "365f20b90286"
},
"index" : {
"size" : {
"total_in_bytes" : 0,
"reused_in_bytes" : 0,
"recovered_in_bytes" : 0,
"percent" : "0.0%"
},
"files" : {
"total" : 0,
"reused" : 0,
"recovered" : 0,
"percent" : "0.0%"
},
"total_time_in_millis" : 62,
"source_throttle_time_in_millis" : 0,
"target_throttle_time_in_millis" : 0
},
"translog" : {
"recovered" : 0,
"total" : 0,
"percent" : "100.0%",
"total_on_start" : 0,
"total_time_in_millis" : 42
},
"verify_index" : {
"check_index_time_in_millis" : 0,
"total_time_in_millis" : 0
}
},
{
"id" : 0,
"type" : "EMPTY_STORE",
"stage" : "DONE",
"primary" : true,
"start_time_in_millis" : 1698130829110,
"stop_time_in_millis" : 1698130829217,
"total_time_in_millis" : 107,
"source" : { },
"target" : {
"id" : "sby8CsbPRPKoXSyNT9r6Ow",
"host" : "172.17.0.2",
"transport_address" : "172.17.0.2:9300",
"ip" : "172.17.0.2",
"name" : "365f20b90286"
},
"index" : {
"size" : {
"total_in_bytes" : 0,
"reused_in_bytes" : 0,
"recovered_in_bytes" : 0,
"percent" : "0.0%"
},
"files" : {
"total" : 0,
"reused" : 0,
"recovered" : 0,
"percent" : "0.0%"
},
"total_time_in_millis" : 59,
"source_throttle_time_in_millis" : 0,
"target_throttle_time_in_millis" : 0
},
"translog" : {
"recovered" : 0,
"total" : 0,
"percent" : "100.0%",
"total_on_start" : 0,
"total_time_in_millis" : 39
},
"verify_index" : {
"check_index_time_in_millis" : 0,
"total_time_in_millis" : 0
}
}
]
}
}
5、索引的统计指标
Elasticsearch提供了一个统计指标的查看端点,通过该端点可以查看每个索引的统计数据,其调用方法如下
GET order001/_stats
以上这个请求查询了索引order001的统计指标,返回的结果如下
{
"_shards" : {
"total" : 6,
"successful" : 3,
"failed" : 0
},
"_all" : {
"primaries" : {
"docs" : {
"count" : 0,
"deleted" : 0
},
"store" : {
"size_in_bytes" : 624,
"reserved_in_bytes" : 0
},
"indexing" : {
"index_total" : 0,
"index_time_in_millis" : 0,
"index_current" : 0,
"index_failed" : 0,
"delete_total" : 0,
"delete_time_in_millis" : 0,
"delete_current" : 0,
"noop_update_total" : 0,
"is_throttled" : false,
"throttle_time_in_millis" : 0
},
"get" : {
"total" : 0,
"time_in_millis" : 0,
"exists_total" : 0,
"exists_time_in_millis" : 0,
"missing_total" : 0,
"missing_time_in_millis" : 0,
"current" : 0
},
"search" : {
"open_contexts" : 0,
"query_total" : 0,
"query_time_in_millis" : 0,
"query_current" : 0,
"fetch_total" : 0,
"fetch_time_in_millis" : 0,
"fetch_current" : 0,
"scroll_total" : 0,
"scroll_time_in_millis" : 0,
"scroll_current" : 0,
"suggest_total" : 0,
"suggest_time_in_millis" : 0,
"suggest_current" : 0
},
"merges" : {
"current" : 0,
"current_docs" : 0,
"current_size_in_bytes" : 0,
"total" : 0,
"total_time_in_millis" : 0,
"total_docs" : 0,
"total_size_in_bytes" : 0,
"total_stopped_time_in_millis" : 0,
"total_throttled_time_in_millis" : 0,
"total_auto_throttle_in_bytes" : 62914560
},
"refresh" : {
"total" : 6,
"total_time_in_millis" : 0,
"external_total" : 6,
"external_total_time_in_millis" : 0,
"listeners" : 0
},
"flush" : {
"total" : 3,
"periodic" : 0,
"total_time_in_millis" : 0
},
"warmer" : {
"current" : 0,
"total" : 3,
"total_time_in_millis" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 0,
"total_count" : 0,
"hit_count" : 0,
"miss_count" : 0,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 0,
"memory_in_bytes" : 0,
"terms_memory_in_bytes" : 0,
"stored_fields_memory_in_bytes" : 0,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 0,
"points_memory_in_bytes" : 0,
"doc_values_memory_in_bytes" : 0,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 0,
"max_unsafe_auto_id_timestamp" : -1,
"file_sizes" : { }
},
"translog" : {
"operations" : 0,
"size_in_bytes" : 165,
"uncommitted_operations" : 0,
"uncommitted_size_in_bytes" : 165,
"earliest_last_modified_age" : 0
},
"request_cache" : {
"memory_size_in_bytes" : 0,
"evictions" : 0,
"hit_count" : 0,
"miss_count" : 0
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
},
"total" : {
"docs" : {
"count" : 0,
"deleted" : 0
},
"store" : {
"size_in_bytes" : 624,
"reserved_in_bytes" : 0
},
"indexing" : {
"index_total" : 0,
"index_time_in_millis" : 0,
"index_current" : 0,
"index_failed" : 0,
"delete_total" : 0,
"delete_time_in_millis" : 0,
"delete_current" : 0,
"noop_update_total" : 0,
"is_throttled" : false,
"throttle_time_in_millis" : 0
},
"get" : {
"total" : 0,
"time_in_millis" : 0,
"exists_total" : 0,
"exists_time_in_millis" : 0,
"missing_total" : 0,
"missing_time_in_millis" : 0,
"current" : 0
},
"search" : {
"open_contexts" : 0,
"query_total" : 0,
"query_time_in_millis" : 0,
"query_current" : 0,
"fetch_total" : 0,
"fetch_time_in_millis" : 0,
"fetch_current" : 0,
"scroll_total" : 0,
"scroll_time_in_millis" : 0,
"scroll_current" : 0,
"suggest_total" : 0,
"suggest_time_in_millis" : 0,
"suggest_current" : 0
},
"merges" : {
"current" : 0,
"current_docs" : 0,
"current_size_in_bytes" : 0,
"total" : 0,
"total_time_in_millis" : 0,
"total_docs" : 0,
"total_size_in_bytes" : 0,
"total_stopped_time_in_millis" : 0,
"total_throttled_time_in_millis" : 0,
"total_auto_throttle_in_bytes" : 62914560
},
"refresh" : {
"total" : 6,
"total_time_in_millis" : 0,
"external_total" : 6,
"external_total_time_in_millis" : 0,
"listeners" : 0
},
"flush" : {
"total" : 3,
"periodic" : 0,
"total_time_in_millis" : 0
},
"warmer" : {
"current" : 0,
"total" : 3,
"total_time_in_millis" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 0,
"total_count" : 0,
"hit_count" : 0,
"miss_count" : 0,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 0,
"memory_in_bytes" : 0,
"terms_memory_in_bytes" : 0,
"stored_fields_memory_in_bytes" : 0,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 0,
"points_memory_in_bytes" : 0,
"doc_values_memory_in_bytes" : 0,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 0,
"max_unsafe_auto_id_timestamp" : -1,
"file_sizes" : { }
},
"translog" : {
"operations" : 0,
"size_in_bytes" : 165,
"uncommitted_operations" : 0,
"uncommitted_size_in_bytes" : 165,
"earliest_last_modified_age" : 0
},
"request_cache" : {
"memory_size_in_bytes" : 0,
"evictions" : 0,
"hit_count" : 0,
"miss_count" : 0
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
}
},
"indices" : {
"order001" : {
"uuid" : "n58cYBLMQiehern0D36c-A",
"primaries" : {
"docs" : {
"count" : 0,
"deleted" : 0
},
"store" : {
"size_in_bytes" : 624,
"reserved_in_bytes" : 0
},
"indexing" : {
"index_total" : 0,
"index_time_in_millis" : 0,
"index_current" : 0,
"index_failed" : 0,
"delete_total" : 0,
"delete_time_in_millis" : 0,
"delete_current" : 0,
"noop_update_total" : 0,
"is_throttled" : false,
"throttle_time_in_millis" : 0
},
"get" : {
"total" : 0,
"time_in_millis" : 0,
"exists_total" : 0,
"exists_time_in_millis" : 0,
"missing_total" : 0,
"missing_time_in_millis" : 0,
"current" : 0
},
"search" : {
"open_contexts" : 0,
"query_total" : 0,
"query_time_in_millis" : 0,
"query_current" : 0,
"fetch_total" : 0,
"fetch_time_in_millis" : 0,
"fetch_current" : 0,
"scroll_total" : 0,
"scroll_time_in_millis" : 0,
"scroll_current" : 0,
"suggest_total" : 0,
"suggest_time_in_millis" : 0,
"suggest_current" : 0
},
"merges" : {
"current" : 0,
"current_docs" : 0,
"current_size_in_bytes" : 0,
"total" : 0,
"total_time_in_millis" : 0,
"total_docs" : 0,
"total_size_in_bytes" : 0,
"total_stopped_time_in_millis" : 0,
"total_throttled_time_in_millis" : 0,
"total_auto_throttle_in_bytes" : 62914560
},
"refresh" : {
"total" : 6,
"total_time_in_millis" : 0,
"external_total" : 6,
"external_total_time_in_millis" : 0,
"listeners" : 0
},
"flush" : {
"total" : 3,
"periodic" : 0,
"total_time_in_millis" : 0
},
"warmer" : {
"current" : 0,
"total" : 3,
"total_time_in_millis" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 0,
"total_count" : 0,
"hit_count" : 0,
"miss_count" : 0,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 0,
"memory_in_bytes" : 0,
"terms_memory_in_bytes" : 0,
"stored_fields_memory_in_bytes" : 0,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 0,
"points_memory_in_bytes" : 0,
"doc_values_memory_in_bytes" : 0,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 0,
"max_unsafe_auto_id_timestamp" : -1,
"file_sizes" : { }
},
"translog" : {
"operations" : 0,
"size_in_bytes" : 165,
"uncommitted_operations" : 0,
"uncommitted_size_in_bytes" : 165,
"earliest_last_modified_age" : 0
},
"request_cache" : {
"memory_size_in_bytes" : 0,
"evictions" : 0,
"hit_count" : 0,
"miss_count" : 0
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
},
"total" : {
"docs" : {
"count" : 0,
"deleted" : 0
},
"store" : {
"size_in_bytes" : 624,
"reserved_in_bytes" : 0
},
"indexing" : {
"index_total" : 0,
"index_time_in_millis" : 0,
"index_current" : 0,
"index_failed" : 0,
"delete_total" : 0,
"delete_time_in_millis" : 0,
"delete_current" : 0,
"noop_update_total" : 0,
"is_throttled" : false,
"throttle_time_in_millis" : 0
},
"get" : {
"total" : 0,
"time_in_millis" : 0,
"exists_total" : 0,
"exists_time_in_millis" : 0,
"missing_total" : 0,
"missing_time_in_millis" : 0,
"current" : 0
},
"search" : {
"open_contexts" : 0,
"query_total" : 0,
"query_time_in_millis" : 0,
"query_current" : 0,
"fetch_total" : 0,
"fetch_time_in_millis" : 0,
"fetch_current" : 0,
"scroll_total" : 0,
"scroll_time_in_millis" : 0,
"scroll_current" : 0,
"suggest_total" : 0,
"suggest_time_in_millis" : 0,
"suggest_current" : 0
},
"merges" : {
"current" : 0,
"current_docs" : 0,
"current_size_in_bytes" : 0,
"total" : 0,
"total_time_in_millis" : 0,
"total_docs" : 0,
"total_size_in_bytes" : 0,
"total_stopped_time_in_millis" : 0,
"total_throttled_time_in_millis" : 0,
"total_auto_throttle_in_bytes" : 62914560
},
"refresh" : {
"total" : 6,
"total_time_in_millis" : 0,
"external_total" : 6,
"external_total_time_in_millis" : 0,
"listeners" : 0
},
"flush" : {
"total" : 3,
"periodic" : 0,
"total_time_in_millis" : 0
},
"warmer" : {
"current" : 0,
"total" : 3,
"total_time_in_millis" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 0,
"total_count" : 0,
"hit_count" : 0,
"miss_count" : 0,
"cache_size" : 0,
"cache_count" : 0,
"evictions" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 0,
"evictions" : 0
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 0,
"memory_in_bytes" : 0,
"terms_memory_in_bytes" : 0,
"stored_fields_memory_in_bytes" : 0,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 0,
"points_memory_in_bytes" : 0,
"doc_values_memory_in_bytes" : 0,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 0,
"max_unsafe_auto_id_timestamp" : -1,
"file_sizes" : { }
},
"translog" : {
"operations" : 0,
"size_in_bytes" : 165,
"uncommitted_operations" : 0,
"uncommitted_size_in_bytes" : 165,
"earliest_last_modified_age" : 0
},
"request_cache" : {
"memory_size_in_bytes" : 0,
"evictions" : 0,
"hit_count" : 0,
"miss_count" : 0
},
"recovery" : {
"current_as_source" : 0,
"current_as_target" : 0,
"throttle_time_in_millis" : 0
}
}
}
}
}
其中,_all中的内容是两个索引的统计数据,indices里面包含每个索引单独的统计数据。在每个索引的统计数据中,又包含主分片(primaries)的统计数据和全部分片(total)的统计数据。stats端点的索引的统计数据的指标如图
如果觉得返回的指标太多,你可以通过传参来指定需要查看的统计指标,以下请求只查看索引段合并与刷新次数的统计数据
GET /order001/_stats/merge,refresh