查看原文
其他

ElasticSearch 集群监控

zhisheng zhisheng 2021-09-05


最近在做 ElasticSearch 的信息(集群和节点)监控,特此稍微整理下学到的东西。这篇文章主要介绍集群的监控。

要监控哪些 ElasticSearch metrics

Elasticsearch 提供了大量的 Metric,可以帮助您检测到问题的迹象,在遇到节点不可用、out-of-memory、long garbage collection times 的时候采取相应措施。但是指标太多了,有时我们并不需要这么多,这就需要我们进行筛选。

集群健康

一个 Elasticsearch 集群至少包括一个节点和一个索引。或者它 可能有一百个数据节点、三个单独的主节点,以及一小打客户端节点——这些共同操作一千个索引(以及上万个分片)。

不管集群扩展到多大规模,你都会想要一个快速获取集群状态的途径。 ClusterHealth API 充当的就是这个角色。你可以把它想象成是在一万英尺的高度鸟瞰集群。它可以告诉你安心吧一切都好,或者警告你集群某个地方有问题。

让我们执行一下 cluster-health API 然后看看响应体是什么样子的:

  1. GET _cluster/health

和 Elasticsearch 里其他 API 一样, cluster-health 会返回一个 JSON 响应。这对自动化和告警系统来说,非常便于解析。响应中包含了和你集群有关的一些关键信息:

  1. {

  2.   "cluster_name": "elasticsearch_zach",

  3.   "status": "green",

  4.   "timed_out": false,

  5.   "number_of_nodes": 1,

  6.   "number_of_data_nodes": 1,

  7.   "active_primary_shards": 10,

  8.   "active_shards": 10,

  9.   "relocating_shards": 0,

  10.   "initializing_shards": 0,

  11.   "unassigned_shards": 0

  12. }

响应信息中最重要的一块就是 status 字段。状态可能是三个值。

集群统计信息包含 集群的分片数,文档数,存储空间,缓存信息,内存作用率,插件内容,文件系统内容,JVM 作用状况,系统 CPU,OS 信息,段信息。

查看全部统计信息命令:

  1. curl -XGET 'http://localhost:9200/_cluster/stats?human&pretty'

返回 JSON 结果:

  1. {

  2.   "timestamp": 1459427693515,

  3.   "cluster_name": "elasticsearch",

  4.   "status": "green",

  5.   "indices": {

  6.      "count": 2,

  7.      "shards": {

  8.         "total": 10,

  9.         "primaries": 10,

  10.         "replication": 0,

  11.         "index": {

  12.            "shards": {

  13.               "min": 5,

  14.               "max": 5,

  15.               "avg": 5

  16.            },

  17.            "primaries": {

  18.               "min": 5,

  19.               "max": 5,

  20.               "avg": 5

  21.            },

  22.            "replication": {

  23.               "min": 0,

  24.               "max": 0,

  25.               "avg": 0

  26.            }

  27.         }

  28.      },

  29.      "docs": {

  30.         "count": 10,

  31.         "deleted": 0

  32.      },

  33.      "store": {

  34.         "size": "16.2kb",

  35.         "size_in_bytes": 16684,

  36.         "throttle_time": "0s",

  37.         "throttle_time_in_millis": 0

  38.      },

  39.      "fielddata": {

  40.         "memory_size": "0b",

  41.         "memory_size_in_bytes": 0,

  42.         "evictions": 0

  43.      },

  44.      "query_cache": {

  45.         "memory_size": "0b",

  46.         "memory_size_in_bytes": 0,

  47.         "total_count": 0,

  48.         "hit_count": 0,

  49.         "miss_count": 0,

  50.         "cache_size": 0,

  51.         "cache_count": 0,

  52.         "evictions": 0

  53.      },

  54.      "completion": {

  55.         "size": "0b",

  56.         "size_in_bytes": 0

  57.      },

  58.      "segments": {

  59.         "count": 4,

  60.         "memory": "8.6kb",

  61.         "memory_in_bytes": 8898,

  62.         "terms_memory": "6.3kb",

  63.         "terms_memory_in_bytes": 6522,

  64.         "stored_fields_memory": "1.2kb",

  65.         "stored_fields_memory_in_bytes": 1248,

  66.         "term_vectors_memory": "0b",

  67.         "term_vectors_memory_in_bytes": 0,

  68.         "norms_memory": "384b",

  69.         "norms_memory_in_bytes": 384,

  70.         "doc_values_memory": "744b",

  71.         "doc_values_memory_in_bytes": 744,

  72.         "index_writer_memory": "0b",

  73.         "index_writer_memory_in_bytes": 0,

  74.         "version_map_memory": "0b",

  75.         "version_map_memory_in_bytes": 0,

  76.         "fixed_bit_set": "0b",

  77.         "fixed_bit_set_memory_in_bytes": 0,

  78.         "file_sizes": {}

  79.      },

  80.      "percolator": {

  81.         "num_queries": 0

  82.      }

  83.   },

  84.   "nodes": {

  85.      "count": {

  86.         "total": 1,

  87.         "data": 1,

  88.         "coordinating_only": 0,

  89.         "master": 1,

  90.         "ingest": 1

  91.      },

  92.      "versions": [

  93.         "5.6.3"

  94.      ],

  95.      "os": {

  96.         "available_processors": 8,

  97.         "allocated_processors": 8,

  98.         "names": [

  99.            {

  100.               "name": "Mac OS X",

  101.               "count": 1

  102.            }

  103.         ],

  104.         "mem" : {

  105.            "total" : "16gb",

  106.            "total_in_bytes" : 17179869184,

  107.            "free" : "78.1mb",

  108.            "free_in_bytes" : 81960960,

  109.            "used" : "15.9gb",

  110.            "used_in_bytes" : 17097908224,

  111.            "free_percent" : 0,

  112.            "used_percent" : 100

  113.         }

  114.      },

  115.      "process": {

  116.         "cpu": {

  117.            "percent": 9

  118.         },

  119.         "open_file_descriptors": {

  120.            "min": 268,

  121.            "max": 268,

  122.            "avg": 268

  123.         }

  124.      },

  125.      "jvm": {

  126.         "max_uptime": "13.7s",

  127.         "max_uptime_in_millis": 13737,

  128.         "versions": [

  129.            {

  130.               "version": "1.8.0_74",

  131.               "vm_name": "Java HotSpot(TM) 64-Bit Server VM",

  132.               "vm_version": "25.74-b02",

  133.               "vm_vendor": "Oracle Corporation",

  134.               "count": 1

  135.            }

  136.         ],

  137.         "mem": {

  138.            "heap_used": "57.5mb",

  139.            "heap_used_in_bytes": 60312664,

  140.            "heap_max": "989.8mb",

  141.            "heap_max_in_bytes": 1037959168

  142.         },

  143.         "threads": 90

  144.      },

  145.      "fs": {

  146.         "total": "200.6gb",

  147.         "total_in_bytes": 215429193728,

  148.         "free": "32.6gb",

  149.         "free_in_bytes": 35064553472,

  150.         "available": "32.4gb",

  151.         "available_in_bytes": 34802409472

  152.      },

  153.      "plugins": [

  154.        {

  155.          "name": "analysis-icu",

  156.          "version": "5.6.3",

  157.          "description": "The ICU Analysis plugin integrates Lucene ICU module into elasticsearch, adding ICU relates analysis components.",

  158.          "classname": "org.elasticsearch.plugin.analysis.icu.AnalysisICUPlugin",

  159.          "has_native_controller": false

  160.        },

  161.        {

  162.          "name": "ingest-geoip",

  163.          "version": "5.6.3",

  164.          "description": "Ingest processor that uses looksup geo data based on ip adresses using the Maxmind geo database",

  165.          "classname": "org.elasticsearch.ingest.geoip.IngestGeoIpPlugin",

  166.          "has_native_controller": false

  167.        },

  168.        {

  169.          "name": "ingest-user-agent",

  170.          "version": "5.6.3",

  171.          "description": "Ingest processor that extracts information from a user agent",

  172.          "classname": "org.elasticsearch.ingest.useragent.IngestUserAgentPlugin",

  173.          "has_native_controller": false

  174.        }

  175.      ]

  176.   }

  177. }

内存使用和 GC 指标

在运行 Elasticsearch 时,内存是您要密切监控的关键资源之一。 Elasticsearch 和 Lucene 以两种方式利用节点上的所有可用 RAM:JVM heap 和文件系统缓存。 Elasticsearch 运行在Java虚拟机(JVM)中,这意味着JVM垃圾回收的持续时间和频率将成为其他重要的监控领域。

上面返回的 JSON监控的指标有我个人觉得有这些:

  • nodes.successful

  • nodes.failed

  • nodes.total

  • nodes.mem.used_percent

  • nodes.process.cpu.percent

  • nodes.jvm.mem.heap_used

可以看到 JSON 文件是很复杂的,如果从这复杂的 JSON 中获取到对应的指标(key)的值呢,这里请看文章 :JsonPath —— JSON 解析神器

最后

这里主要讲下 ES 集群的一些监控信息,有些监控指标是个人觉得需要监控的,但是具体情况还是得看需求了。下篇文章主要讲节点的监控信息。转载请注明地址:http://www.54tianzhisheng.cn/2017/10/15/ElasticSearch-cluster-health-metrics/

参考资料

1、How to monitor Elasticsearch performance

2、ElasticSearch 性能监控

3、cluster-health

4、cluster-stats

相关阅读

1、Elasticsearch 默认分词器和中分分词器之间的比较及使用方法

2、全文搜索引擎 Elasticsearch 集群搭建入门教程

关注我

: . Video Mini Program Like ,轻点两下取消赞 Wow ,轻点两下取消在看

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存