在Elasticsearch提供了一套精简API来查看系统的状态,官方的文档叫cat API。主要的目的是由于Elasticsearch默认提供的接口返回都是JSON格式的,这种格式不利于人类的阅读,所以搞出来一套cat API来简化。

    每个命令都是以/_cat开头,可以接收v参数得到详细输出;可以通过help参数得到返回的每列的帮助信息。可以通h=参数名返回部分内容,多个参数可以用逗号分开,甚至可以支持通配符。例如:

请求:GET http://127.0.0.1:9200/_cat/master?v

返回:

id                     host      ip        node    

jevOQqVQT_a_pAGqKA0p7w 127.0.0.1 127.0.0.1 Artemis

查询帮助实例:

请求:GET http://127.0.0.1:9200/_cat/master?help

id   |   | node id    

host | h | host name  

ip   |   | ip address 

node | n | node name  


指标 说明

aliases 别名显示有关的别名的一些信息,包括过滤和路由等信息,可以在最后面加上具体别名的名称单独查询某个具体的别名。

allocation 在分配给每个数据节点上提供多少分片快照和他们使用的磁盘空间有多大。

count 提供节点的文档总数,如果后面加上索引名称,可以的得到具体索引的文档数量。

fielddata 在集群中的每个数据节点上正在使用的堆内存的大小。

health 提供集群的健康情况。

indices 提供节点下的索引信息,可以得到索引的分片,文档,存储大小等信息。

master 显示master节点的概要信息,主要是id,ip和节点名称。

nodeattrs 显示自定义节点属性。

nodes 显示节点相关的信息。

pending tasks 集群任务接口,和集群接口类似,参见集群任务文档。

plugins 提供激情群中插件安装的信息。

recovery 正在进行和以前完成的索引分片的回收率。

repositories 显示在群集中注册的快照库。

thread pool 显示每个群集节点的线程池统计。

shards 索引分片的使用情况。分片有很多的指标,可以用help查看。

segments 每个索引分片中低水平段的信息

snapshots 显示仓库的快照信息。

本文由赛克 蓝德(secisland)原创,转载请标明作者和出处。


indices

indices有非常多的参数可以选择,具体用help查看。例如:

请求:GET http://127.0.0.1:9200/_cat/indices?pri&v&h=health,index,prirep,docs.count,mt


返回的结果:

health index     docs.count mt pri.mt 

yellow customer           5  0      0 

green  .scripts           2  0      0 

green  secilog            2  0      0 

yellow secisland          4  0      0

nodes


nodes有非常多的参数可以选择,具体用help查看。例如:

请求:GET http://127.0.0.1:9200/_cat/nodes?v&h=id,ip,port,v,m,jdk


返回的结果:

id   ip        port v     m jdk      

qKTT 127.0.0.1 9300 2.2.0 * 1.7.0_79

回复命令recovery

    在一个集群中,一个索引的分片可能随时会从一个节点迁移到另一个节点,比如在恢复快照的过程中,新节点启动的过程中等等。例如下面的示例表示没有任何分片的数据在传输:


请求:GET http://127.0.0.1:9200/_cat/recovery/secisland?v

返回的结果:

index     shard time type  stage source_host target_host repository snapshot files files_percent bytes bytes_percent total_files total_bytes translog translog_percent total_translog 

secisland 0     115  store done  127.0.0.1   127.0.0.1   n/a        n/a      0     100.0%        0     100.0%        1           159         0        -1.0%            -1             

secisland 1     15   store done  127.0.0.1   127.0.0.1   n/a        n/a      0     100.0%        0     100.0%        1           159         0        -1.0%            -1             

secisland 2     55   store done  127.0.0.1   127.0.0.1   n/a        n/a      0     100.0%        0     100.0%        7           6784        0        -1.0%            -1             

secisland 3     51   store done  127.0.0.1   127.0.0.1   n/a        n/a      0     100.0%        0     100.0%        4           3468        0        -1.0%            -1             

secisland 4     182  store done  127.0.0.1   127.0.0.1   n/a        n/a      0     100.0%        0     100.0%        4           3468        0        -1.0%            -1

通过增加副本节点的数量可以让分片的数据进行传输。


例如:

index shard time type    stage source target files percent bytes     percent

wiki  0     1252 store done  hostA  hostA  4     100.0%  23638870 100.0%

wiki  0     1672 replica index hostA  hostB  4     75.0%   23638870 48.8%

wiki  1     1698 replica index hostA  hostB  4     75.0%   23348540 49.4%

wiki  1     4812 store done  hostA  hostA  33    100.0%  24501912 100.0%

wiki  2     1689 replica index hostA  hostB  4     75.0%   28681851 40.2%

wiki  2     5317 store done  hostA  hostA  36    100.0%  30267222 100.0%

线程池

线程池有非常多的参数可以选择,具体用help查看。例如:


请求:GET http://127.0.0.1:9200/_cat/thread_pool?v&h=id,host,suggest.active,suggest.rejected,suggest.completed


返回的结果:

id   host      suggest.active suggest.rejected suggest.completed 

qKTT 127.0.0.1         0            0             0

    赛克蓝德(secisland)后续会逐步对Elasticsearch的最新版本的各项功能进行分析,近请期待。也欢迎加入secisland公众号进行关注。