[Elasticsearch Monitor] 如何監控Elasticsearch(二)

上一篇文章如何監控Elasticsearch主要描述了對于Es服務器應該監控哪些指標。本文旨在介紹es api中的各統計指標含義。

Elasticsearch’s RESTful API + JSON

默認情況下,Elasticsearch在9200端口上提供了restful http服務,返回集群,節點,索引狀況的JSON結果。主要有五個HTTP REST API可用于監視Elasticsearch:

  • Cluster Health API
  • Cluster Stats API
  • Node Stats API
  • Index Stats API
  • Pending Tasks API

下面的表格總結了上一篇文章中提到搜索性能,索引性能,內存性能,網絡性能對應的ES API。其中有些性能數據是從多個維度描述的,比如搜索性能在節點維度和索引維度都有提供。

Metric category Availability
Search performance metrics Node Stats API, Index Stats API
Indexing performance metrics Node Stats API, Index Stats API
Memory and garbage collection Node Stats API, Cluster Stats API
Network metrics Node Stats API
Cluster health and node availability Cluster Health API
Resource saturation and errors Node Stats API, Index Stats API, Cluster Stats API, Pending Tasks API

(一)Cluster Health API

Cluster Health API提供了描述集群健康狀態的JSON對象數據。

API接口:

GET _cluster/health

返回結果JSON:

{
  "cluster_name": "elasticsearch",
  "status": "yellow",
  "timed_out": false,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "active_primary_shards": 11,
  "active_shards": 11,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 10,
  "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": 52.38095238095239
}
  • status一共有3個狀態:green表示所有主分片及備份分片都分配好了,集群100%健康。yellow表示所有主分片都分配好了,但至少有一個備份分片未分配。數據沒有丟失,搜索結果是完整的。但高可用性會缺失,存在丟失數據風險,以黃色表示警告。red表示至少有一個主分片未分配,并且這個主分片的所有分片都丟失了。數據已經丟失了,搜索結果不完整,并且往這個分片索引數據會發生異常。
  • number_of_nodesnumber_of_data_nodes,從名字就可以知道分別是節點數和數據節點數。
  • active_primary_shards,集群中所有index的主分片數量的總和。
  • active_shards,集群中所有index的分片數量的總和,包括備份分片。
  • relocating_shards,正在被移動的分片數量。通常為0,在集群rebalance的時候會有變化。

(二)Cluster Stats API

Cluster Stats API提供了集群維度的信息。基本上是Node Stats API的數據的總和。雖然沒有每個節點的詳細信息,但是可以讓你快速了解掌握整個集群當前的運行狀態。

API接口:

GET _cluster/stats
{
  "_nodes": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "cluster_name": "elasticsearch",
  "timestamp": 1500175210218,
  "status": "yellow",
  "indices": {
    "count": 11,
    "shards": {...},
    "docs": {...},
    "store": {...},
    "fielddata": {...},
    "query_cache": {...},
    "completion": {...},
    "segments": {...}
  },
  "nodes": {
    "count": {...},
    "versions": [...],
    "os": {...},
    "process": {...},
    "jvm": {...},
    "fs": {...},
    "plugins": [...],
    "network_types": {...}
  }
}

對于indices和nodes內部屬性的含義會在Node Stats API里介紹

(三)Node Stats API

Node Stats API是一個非常有用的API,用于監控集群每臺服務器的狀態。它統計了我們想要監控的主要的那些指標,包括了我們上一篇列舉的大部分指標。

API接口:

GET _nodes/stats (或者指定node獲取 _nodes/node1,node2/stats)
{
  "_nodes": {
    "total": 1,
    "successful": 1,
    "failed": 0
  },
  "cluster_name": "elasticsearch",
  "nodes": {
    "SdRLvOO7RKSiaBW_hmwvZg": {
      "name": "node1",
      "indices": {...},
      "os": {...},
      "process": {...},
      "jvm": {...},
      "thread_pool": {...},
      "fs": {...},
      "transport": {...},
      "http": {...}
    }
    ...
  }
}
  • 查詢性能指標,前綴indices.search.*的指標
    • indices.search.query_total 查詢總量
    • indices.search.query_time_in_millis 查詢總耗時
    • indices.search.query_current 正在處理的查詢量
    • indices.search.fetch_total 查詢的第二階段fetch總量
    • indices.search.fetch_time_in_millis fetch耗時
    • indices.search.fetch_current 正在處理的fetch數量
  • 索引性能指標,前綴indices.indexing.* ,indices.refresh.* ,indices.flush.* 的指標
    • indices.indexing.index_total 索引總量
    • indices.indexing.index_time_in_millis 索引耗時
    • indices.indexing.index_current 正在處理的索引量
    • indices.refresh.total 刷新內存總量
    • indices.refresh.total_time_in_millis 刷新內存耗時
    • indices.flush.total 同步磁盤總量
    • indices.flush.total_time_in_millis 同步磁盤耗時
  • Cache性能指標,前綴indices.query_cache.* ,indices.fielddata.* ,indices.request_cache.* 的指標。fielddata可能會成為內存消耗大戶,需要特別注意
    • indices.query_cache.memory_size_in_bytes 查詢緩存大小
    • indices.query_cache.evictions 查詢緩存剔除大小
    • indices.fielddata.memory_size_in_bytes fielddata緩存大小
    • indices.fielddata.evictions fielddata緩存剔除大小
    • indices.request_cache.memory_size_in_bytes 所有請求緩存大小
    • indices.request_cache.evictions 所有請求緩存剔除大小
  • os指標
    • os.cpu.percent 系統CPU使用百分比
    • os.cpu.load_average.1m 系統CPU 1分鐘平均load
    • os.cpu.load_average.5m 系統CPU 5分鐘平均load
    • os.cpu.load_average.15m 系統CPU 15分鐘平均load
    • os.mem.free_percent 系統內存可用百分比
    • os.mem.used_percent 系統內存已使用百分比
    • os.mem.total_in_bytes 系統內存總大小
    • os.mem.free_in_bytes 系統內存可用大小
    • os.mem.used_in_bytes 系統內存已使用大小
    • os.swap.total_in_bytes 系統swap總大小
    • os.swap.free_in_bytes 系統swap可用大小
    • os.swap.used_in_bytes 系統swap已使用大小
  • process指標,專用與es jvm進程的資源消耗指標
    • process.cpu.percent 進程CPU使用百分比
    • process.cpu.total_in_millis 進程CPU使用時間
    • process.mem.total_virtual_in_bytes 進程可用虛擬內存大小
    • process.open_file_descriptors 進程打開文件句柄數
    • process.max_file_descriptors 進程可用句柄數
  • JVM性能指標,前綴jvm.*的指標,內存使用及GC指標
    • jvm.gc.collectors.young.collection_count young gc 大小
    • jvm.gc.collectors.young.collection_time_in_millis young gc 耗時
    • jvm.gc.collectors.old.collection_count old gc 大小
    • jvm.gc.collectors.old.collection_time_in_millis old gc 耗時
    • jvm.mem.heap_used_percent 內存使用百分比
    • jvm.mem.heap_used_in_bytes 內存使用量
    • jvm.mem.heap_committed_in_bytes 內存占用量
  • 線程池性能指標,前綴thread_pool.*的指標
    • thread_pool.bulk.queue thread_pool.index.queue thread_pool.search.queue thread_pool.merge.queue 各隊列長度
    • thread_pool.bulk.rejected thread_pool.index.rejected thread_pool.search.rejected thread_pool.merge.rejected 各隊列溢出量(未執行,被放棄)
  • 文件系統指標
    • fs.total.total_in_bytes 數據目錄總大小
    • fs.total.free_in_bytes 數據目錄剩余大小
    • fs.total.vailable_in_bytes 數據目錄可用大小
  • 集群通信指標
    • transport.rx_count 集群通信中接收的數據包總數
    • transport.rx_size_in_bytes 集群通信中接收的數據的總大小
    • transport.tx_count 集群通信中發送的數據包總數
    • transport.tx_size_in_bytes 集群通信中發送的數據的總大小
    • transport.server_open 為集群通信打開的連接數
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容