一、参考资料
http://www.54tianzhisheng.cn/2017/10/18/ElasticSearch-nodes-metrics/
https://www.datadoghq.com/blog/monitor-elasticsearch-performance-metrics/#memory-usage-and-garbage-collection
二、前言
最近在研究ES集群监控方面的内容,结合公司目前的监控方案和外界的一些资料做了一些知识点的梳理和总结。
三、内容
ES监控的最主要作用是用于保障基于ES的服务正常运行以及在出现问题时为工程师提供解决问题的依据。综合我调查了的各类监控方案来说,目前ES监控主要针对三个级别,分别是集群级别、节点级别和索引级别。集群级别的监控主要是针对整个ES集群来说,包括集群的健康状况、集群的状态等。节点级别的监控主要是针对每个ES实例的监控,其中包括每个实例的查询索引指标和物理资源使用指标。索引级别的监控主要是针对每个索引来说,主要包括每个索引的性能指标,由于是针对每个索引的监控,因此一般含有多个索引的ES集群其索引级别的监控数据是非常多的。
针对这三类指标,首先集群级别的指标相较于节点级别和索引级别其量级较少,但是其每个指标都非常重要,可以只看集群级别指标获取ES集群的运行状态。其次,节点级别的指标更多的用于问题的排查,当发现集群出现问题时更可能多的时候会直接定位到具体的ES实例,通过查看单台实例的资源使用情况或者其他指标进行问题排查。最后,索引级别的监控的应用场景主要是为应用提供监控,例如某个应用使用到的索引其查询速度变慢就可以通过索引级别的监控判断是否是由于索引创建时一些不合理设置引起的。针对ES这三类监控内容下面将做更详细总结。
1. 集群监控
集群监控主要包括两个方面的内容,分别是集群健康情况和集群的运行状态。
集群健康状态
集群健康状态可以通过以下api获取:http://ip:9200/_cluster/health?pretty
返回结果示例如下:
{
"cluster_name" : "**** ",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 2,
"number_of_data_nodes" : 2,
"active_primary_shards" : 1280,
"active_shards" : 2549,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 3,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 99.88244514106583
}
关键指标说明:
status:集群状态,分为green、yellow和red。
number_of_nodes/number_of_data_nodes:集群的节点数和数据节点数。
active_primary_shards:集群中所有活跃的主分片数。
active_shards:集群中所有活跃的分片数。
relocating_shards:当前节点迁往其他节点的分片数量,通常为0,当有节点加入或者退出时该值会增加。
initializing_shards:正在初始化的分片。
unassigned_shards:未分配的分片数,通常为0,当有某个节点的副本分片丢失该值就会增加。
number_of_pending_tasks:是指主节点创建索引并分配shards等任务,如果该指标数值一直未减小代表集群存在不稳定因素
active_shards_percent_as_number:集群分片健康度,活跃分片数占总分片数比例。
number_of_pending_tasks:pending task只能由主节点来进行处理,这些任务包括创建索引并将shards分配给节点。
集群状态信息
集群状态信息主要包含整个集群的一些统计信息,例如文档数、分片数、资源使用情况等。集群状态信息可以由以下api获取:http://ip:9200/_cluster/stats?pretty
返回结果示例:
{
"_nodes" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"cluster_name" : "****",
"timestamp" : 1511246201848,
"status" : "yellow",
"indices" : {
"count" : 268,
"shards" : {
"total" : 2629,
"primaries" : 1320,
"replication" : 0.9916666666666667,
"index" : {
"shards" : {
"min" : 1,
"max" : 48,
"avg" : 9.809701492537313
},
"primaries" : {
"min" : 1,
"max" : 24,
"avg" : 4.925373134328358
},
"replication" : {
"min" : 0.0,
"max" : 1.0,
"avg" : 0.9888059701492538
}
}
},
"docs" : {
"count" : 24331382,
"deleted" : 1275153
},
"store" : {
"size_in_bytes" : 14053778191,
"throttle_time_in_millis" : 0
},
"fielddata" : {
"memory_size_in_bytes" : 1172464,
"evictions" : 0
},
"query_cache" : {
"memory_size_in_bytes" : 39586256,
"total_count" : 2292448334,
"hit_count" : 28324446,
"miss_count" : 2264123888,
"cache_size" : 15576,
"cache_count" : 484739,
"evictions" : 469163
},
"completion" : {
"size_in_bytes" : 0
},
"segments" : {
"count" : 6575,
"memory_in_bytes" : 112649529,
"terms_memory_in_bytes" : 90138494,
"stored_fields_memory_in_bytes" : 6917880,
"term_vectors_memory_in_bytes" : 0,
"norms_memory_in_bytes" : 3823616,
"points_memory_in_bytes" : 3450143,
"doc_values_memory_in_bytes" : 8319396,
"index_writer_memory_in_bytes" : 0,
"version_map_memory_in_bytes" : 0,
"fixed_bit_set_memory_in_bytes" : 143704,
"max_unsafe_auto_id_timestamp" : 1510727090177,
"file_sizes" : { }
}
},
"nodes" : {
"count" : {
"total" : 2,
"data" : 2,
"coordinating_only" : 0,
"master" : 2,
"ingest" : 2
},
"versions" : [
"5.4.1"
],
"os" : {
"available_processors" : 64,
"allocated_processors" : 64,
"names" : [
{
"name" : "Linux",
"count" : 2
}
],
"mem" : {
"total_in_bytes" : 269956005888,
"free_in_bytes" : 1114628096,
"used_in_bytes" : 268841377792,
"free_percent" : 0,
"used_percent" : 100
}
},
"process" : {
"cpu" : {
"percent" : 0
},
"open_file_descriptors" : {
"min" : 4189,
"max" : 4321,
"avg" : 4255
}
},
"jvm" : {
"max_uptime_in_millis" : 1802902700,
"versions" : [
{
"version" : "1.8.0_92",
"vm_name" : "Java HotSpot(TM) 64-Bit Server VM",
"vm_version" : "25.92-b14",
"vm_vendor" : "Oracle Corporation",
"count" : 2
}
],
"mem" : {
"heap_used_in_bytes" : 15525080840,
"heap_max_in_bytes" : 68318265344
},
"threads" : 558
},
"fs" : {
"total_in_bytes" : 85857402880,
"free_in_bytes" : 52003000320,
"available_in_bytes" : 52003000320,
"spins" : "true"
},
"plugins" : [
{
"name" : "analysis-ik",
"version" : "5.4.1",
"description" : "IK Analyzer for Elasticsearch",
"classname" : "org.elasticsearch.plugin.analysis.ik.AnalysisIkPlugin",
"has_native_controller" : false
}
],
"network_types" : {
"transport_types" : {
"netty4" : 2
},
"http_types" : {
"netty4" : 2
}
}
}
}
关键指标说明:
indices.count:索引总数。
indices.shards.total:分片总数。
indices.shards.primaries:主分片数量。
docs.count:文档总数。
store.size_in_bytes:数据总存储容量。
segments.count:段总数。
nodes.count.total:总节点数。
nodes.count.data:数据节点数。
nodes. process. cpu.percent:节点CPU使用率。
fs.total_in_bytes:文件系统使用总容量。
fs.free_in_bytes:文件系统剩余总容量。
2. 节点监控
节点监控主要针对各个节点,有很多指标对于保证ES集群的稳定运行非常重要。下面对节点监控指标进行介绍。节点指标可以通过以下api获取:http://ip:9200/_nodes/stats?pretty
返回结果示例:
{
"_nodes" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"cluster_name" : "****",
"nodes" : {
"GoFMtzcMSBq14uLgMjUgXQ" : {
"timestamp" : 1511247337198,
"name" : "es-node1",
"transport_address" : "10.202.77.206:9300",
"host" : "10.202.77.206",
"ip" : "10.202.77.206:9300",
"roles" : [
"master",
"data",
"ingest"
],
"attributes" : {
"rack" : "r1"
},
"indices" : {
"docs" : {
"count" : 24315519,
"deleted" : 1285643 },
"store" : {
"size_in_bytes" : 7062401888,
"throttle_time_in_millis" : 0 },
"indexing" : {
"index_total" : 8203153,
"index_time_in_millis" : 4879194,
"index_current" : 0,
"index_failed" : 2,
"delete_total" : 2683650,
"delete_time_in_millis" : 86088,
"delete_current" : 0,
"noop_update_total" : 2160809,
"is_throttled" : false,
"throttle_t