1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Elasticsearch クラスタ API を試していく

Posted at

目的

一般的に クラスタ API は _cat API よりも詳しい状態を取得するために使うようなので、その実際のレスポンスがどのようなものであるかを確認していきます。
クラスタ API は 出力がJSONフォーマットであるということも、_cat API との違いの一つです。
Elasticsearch _cat API を試していく

方法

Dockerで構築したElasticsearch および Kinaba を使います。
APIは Kinaba のConsoleから実行します。
バージョンは 7.8.1 です。

実践

_cluster/health エンドポイント

クラスタの状態をサマリで取得する。よく使う。

入力
GET _cluster/health
出力
{
  "cluster_name" : "es-docker-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 7,
  "active_shards" : 14,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "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" : 100.0
}

ちなみに、_cat API の health は以下。見やすさの差はあれど、出力項目にそれほど大きな違いはない。

出力_cat
epoch      timestamp cluster           status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1612869853 11:24:13  es-docker-cluster green           3         3     14   7    0    0        0             0                  -                100.0%
_cluster/state エンドポイント

詳細なクラスタの状態を取得する。
情報量が多いが、クラスタ全体の情報が出力される。

入力
GET _cluster/state
出力
{
  "cluster_name" : "es-docker-cluster",
  "cluster_uuid" : "vlBe6ykwTmGsvtAT1xFGUQ",
  "version" : 169,
  "state_uuid" : "4l5pEnIiRQWANxApYWck9w",
  "master_node" : "eUJQohRmTzK_SyFavIGaVQ",
  "blocks" : { },
  "nodes" : {
    "xeSJ08tnRxyXr0JVxZEiSA" : {
      "name" : "es02",
      "ephemeral_id" : "0Fs39ryoQquiLJmv7MDjxw",
      "transport_address" : "172.30.10.2:9300",
      "attributes" : {
        "ml.machine_memory" : "1073741824",
        "ml.max_open_jobs" : "20",
        "xpack.installed" : "true",
        "transform.node" : "true"
      }
    },
    "GJCtO6DxTOuAnnB4SushXQ" : {
      "name" : "es03",
      "ephemeral_id" : "TEyZ13sXQ-2Q_NtIfFtzxg",
      "transport_address" : "172.30.10.3:9300",
      "attributes" : {
        "ml.machine_memory" : "1073741824",
        "ml.max_open_jobs" : "20",
        "xpack.installed" : "true",
        "transform.node" : "true"
      }
    },
...
_nodes エンドポイント

ノードの状態を取得する。
Elasticsearch の設定情報はもちろんのこと、jvm の情報(ヒープサイズ)やスレッドープールの情報まで表示される。逆に言うと、それだけの情報をデフォルトで収集しているということになる。

入力
GET _nodes
出力
{
  "_nodes" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "cluster_name" : "es-docker-cluster",
  "nodes" : {
    "GJCtO6DxTOuAnnB4SushXQ" : {
      "name" : "es03",
      "transport_address" : "172.30.10.3:9300",
      "host" : "172.30.10.3",
      "ip" : "172.30.10.3",
      "version" : "7.8.1",
      "build_flavor" : "default",
      "build_type" : "docker",
      "build_hash" : "b5ca9c58fb664ca8bf9e4057fc229b3396bf3a89",
      "total_indexing_buffer" : 53687091,
      "roles" : [
        "data",
        "ingest",
        "master",
        "ml",
        "remote_cluster_client",
        "transform"
      ],
      "attributes" : {
        "ml.machine_memory" : "1073741824",
        "ml.max_open_jobs" : "20",
        "xpack.installed" : "true",
        "transform.node" : "true"
      },
...

ちなみに cat API で取得する node は以下のようなもので簡易なものとなっている。

出力cat
ip          heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172.30.10.2           35          86   4    0.60    0.31     0.18 dilmrt    -      es02
172.30.10.3           67          93   4    0.60    0.31     0.18 dilmrt    -      es03
172.30.10.1           23          92   4    0.60    0.31     0.18 dilmrt    *      es01
_nodes/stats エンドポイント

各ノードの詳細な統計情報を表示するAPIであり、OSレベルでのCPU/memory の使用量、JVM、GCの統計情報、ファイルディスクリプタ数、スレッドープール数などが取得できる。
_nodes エンドポイントの出力結果と何が違うのかを比較するのも面倒なくらい情報量が多い。
運用監視において有用なAPI。

入力
GET _nodes/stats
出力
{
  "_nodes" : {
    "total" : 3,
    "successful" : 3,
    "failed" : 0
  },
  "cluster_name" : "es-docker-cluster",
  "nodes" : {
    "xeSJ08tnRxyXr0JVxZEiSA" : {
      "timestamp" : 1612955445008,
      "name" : "es02",
      "transport_address" : "172.30.10.2:9300",
      "host" : "172.30.10.2",
      "ip" : "172.30.10.2:9300",
      "roles" : [
        "data",
        "ingest",
        "master",
        "ml",
        "remote_cluster_client",
        "transform"
      ],
      "attributes" : {
        "ml.machine_memory" : "1073741824",
        "ml.max_open_jobs" : "20",
        "xpack.installed" : "true",
        "transform.node" : "true"
      },
      "indices" : {
        "docs" : {
          "count" : 47,
          "deleted" : 1
        },
        "store" : {
          "size_in_bytes" : 86058
        },
        "indexing" : {
          "index_total" : 29,
          "index_time_in_millis" : 607,
          "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
        },

これらのAPIは比較的よく利用される。_cat API に比べて情報量が多いため有用ではあるが、それぞれの情報が意味する内容を理解し、選択できるようになるにはある程度の慣れ(時間)が必要。気になる項目をピックアップし、定期的に実行し、結果を比べてみると面白い傾向が見られるかもしれない。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?