elasticsearch【cat API,系统数据】指令汇总

本博文讲述的ES获取系统数据的API是基于Elasticsearch 2.4.1版本的。

0. overview

a. 下面将要介绍的所有的指令,都支持一个查询参数v(verbose),用来显示详细的查询结果。

b. cat的所有指令,都支持一个help参数查询,帮助用户了解cat相关指令都支持那些功能。

c. cat的所有指令,都支持一个h参数的查询,指定指定的列信息进行输出。

例子: 查询输出master的ip以及node name

[elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/master?h=ip,n

  10.xxx.xx.xxx node-es2

1.  help查询参数

下面,就以一个查看当前ES集群master的信息的例子:

[elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/master?help
id | | node id
host | h | host name
ip | | ip address
node | n | node name

上面的输出含义,解释一下,指的是查看master信息时,能得到的帮助内容,cat获取master信息,将会得到master的节点id,即第一行,id:node id;第二行,表示host,可以简写成h,表示host name,第三行,表示master的ip,描述信息ip address, 第四行,node,简写成n,表示节点名字(node name).

不带help查询参数时,得到下面的信息:

[elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/master?v
id host ip node
9gKBOPrEQ0mtGpq8H0mzDg 10.xxx.xx.xxx 10.xxx.xx.xxx node-es2

还有一点,指的重点指出的是,当不输入任何cat的查询目标时,有help与没有help都是一个cat指令的帮助提示,如下:

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat              #此指令与curl http://localhost:9200/_cat?help得到的结果一样
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}

2. aliases指令

aliases指令可以查询出当前索引的filter以及routing所配置的别名信息。

 [root@localhost ~]# curl http://10.90.7.2:9201/_cat/aliases?v
alias index filter routing.index routing.search

上例中,表示我的系统中,没有配置任何的别名,这个在实际生产中,用的不是很多。

3. allocation指令

该指令提供一个快照,反映当前节点有多少个分片(shard)以及用了多少磁盘空间(disk)。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/allocation?v
shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
.7mb .4gb .6gb 49gb 10.xxx.xx.xxx 10.xxx.xx.xxx node-es1
.1mb .4gb .6gb 49gb 10.xxx.xx.xxx 10.xxx.xx.xxx node-es2

4. count指令

该指令可以获取当前集群中有多少个document,类似mysql中有多少条记录,也可以获取指定index的document的数量。

 [root@localhost ~]# curl http://10.90.7.2:9201/_cat/indices?v                   #获取当前系统有多少个index
health status index pri rep docs.count docs.deleted store.size pri.store.size
yellow open megacorp 795b 795b
yellow open tkssearch .2kb .2kb
yellow open test .2kb .2kb
yellow open tk-search11 .2kb .2kb
yellow open cms .1kb .1kb
yellow open tksearch .3kb .3kb
yellow open rest_index .5kb .5kb
yellow open 795b 795b
yellow open 795b 795b
yellow open 795b 795b
yellow open indexdemo .2kb .2kb
yellow open indexdemo—— 795b 795b
yellow open tk-search-module .6kb .6kb
yellow open 795b 795b
yellow open 795b 795b
yellow open tksearch1 .5kb .5kb
yellow open tk-search .2mb .2mb
 [root@localhost ~]# curl http://10.90.7.2:9201/_cat/count?v         #获取当前集群中有多少个document
epoch timestamp count
::
 [root@localhost ~]# curl http://10.90.7.2:9201/_cat/count/tksearch?v    #获取tksearch这个index的document数量
epoch timestamp count
::

5. health指令

该指令反应当前集群的健康指数信息。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
:: tksearch green - 100.0%

6. indices指令,master指令,上面的例子中有所反应,不再举例。

7. nodeattrs指令

该指令可以反应出当前数据节点的属性信息。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/nodeattrs?v
node host ip attr value

注:这里查不到数据,没有弄明白,官网的说明中,有结果,是什么地方配置的问题?

8. node指令

该指令反应出当前集群的拓扑信息。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://10.130.203.111:9200/_cat/nodes?v
host ip heap.percent ram.percent load node.role master name
10.xxx.xx.xxx 10.xxx.xx.xxx 0.00 d m node-es1
10.yyy.yy.yyy 10.yyy.yy.yyy 0.00 d * node-es2

9. pending_tasks指令

该指令反应当前集群有多少任务处在pending状态,与指令/_cluster/pending_tasks的效果一样。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/pending_tasks?v
insertOrder timeInQueue priority source

上例说明没有处在pending状态的任务。

10. plugins指令

该指令提供一个视图,反应当前节点中处在运行状态的插件。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/plugins?v
name component version type url

11. recovery指令

该指令反应当前系统中,索引分片的恢复信息,包括正在进行的以及已经完成了的。恢复,指的是当节点添加或者减少时发生的数据移动造成的。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/recovery?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
tk-search-module store done .xxx.xx.xxx .xxx.xx.xxx n/a n/a 0.0% 0.0% 100.0%
tk-search-module replica done .xxx.xx.xxx .yyy.yy.yyy n/a n/a 100.0% 100.0% 100.0%
tk-search-module replica done .yyy.yy.yyy .xxx.xx.xxx n/a n/a 100.0% 100.0% 100.0%
tk-search-module store done .yyy.yy.yyy .yyy.yy.yyy n/a n/a 0.0% 0.0% 100.0%
tk-search-module store done .xxx.xx.xxx .xxx.xx.xxx n/a n/a 0.0% 0.0% 100.0%
tk-search-module replica done .xxx.xx.xxx .yyy.yy.yyy n/a n/a 100.0% 100.0% 100.0%
tk-search-module replica done .yyy.yy.yyy .xxx.xx.xxx n/a n/a 100.0% 100.0% 100.0%
tk-search-module store done .yyy.yy.yyy .yyy.yy.yyy n/a n/a 0.0% 0.0% 100.0%
tk-search-module store done .xxx.xx.xxx .xxx.xx.xxx n/a n/a 0.0% 0.0% 100.0%
tk-search-module replica done .xxx.xx.xxx .yyy.yy.yyy n/a n/a 100.0% 100.0% 100.0%
tk-search store done .xxx.xx.xxx .xxx.xx.xxx n/a n/a 0.0% 0.0% 100.0%
tk-search replica done .xxx.xx.xxx .yyy.yy.yyy n/a n/a 100.0% 100.0% 100.0%
tk-search replica done .yyy.yy.yyy .xxx.xx.xxx n/a n/a 100.0% 100.0% 100.0%
tk-search store done .yyy.yy.yyy .yyy.yy.yyy n/a n/a 0.0% 0.0% 100.0%
tk-search store done .xxx.xx.xxx .xxx.xx.xxx n/a n/a 0.0% 0.0% 100.0%
tk-search replica done .xxx.xx.xxx .yyy.yy.yyy n/a n/a 100.0% 100.0% 100.0%
tk-search replica done .yyy.yy.yyy .xxx.xx.xxx n/a n/a 100.0% 100.0% 100.0%
tk-search store done .yyy.yy.yyy .yyy.yy.yyy n/a n/a 0.0% 0.0% 100.0%
tk-search store done .xxx.xx.xxx .xxx.xx.xxx n/a n/a 0.0% 0.0% 100.0%
tk-search replica done .xxx.xx.xxx .yyy.yy.yyy n/a n/a 100.0% 100.0% 100.0%

12. repositories指令

该指令反应当前集群中注册了多少个repository。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/repositories?v
id type

上例中表示没有注册repository到集群

13.  thread_pool指令

该指令反应当前集群中的thread pool在每一个节点上的统计信息。 “By default the active, queue and rejected statistics are returned for the bulk, index and search thread pools

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/thread_pool?v
host ip bulk.active bulk.queue bulk.rejected index.active index.queue index.rejected search.active search.queue search.rejected
.yyy.yy.yyy .yyy.yy.yyy
.xxx.xx.xxx .xxx.xx.xxx

14. shards指令

该指令,相对比较重要,反应每个节点有那些分片,告诉我们,那些是主分片,那些是从分片,每个分片的document数量,以及在该节点占用的磁盘空间。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/shards?v
index shard prirep state docs store ip node
tk-search-module p STARTED 159b .xxx.xx.xxx node-es2
tk-search-module r STARTED 159b .yyy.yy.yyy node-es1
tk-search-module r STARTED 159b .xxx.xx.xxx node-es2
tk-search-module p STARTED 159b .yyy.yy.yyy node-es1
tk-search-module r STARTED 159b .xxx.xx.xxx node-es2
tk-search-module p STARTED 159b .yyy.yy.yyy node-es1
tk-search-module p STARTED .4kb .xxx.xx.xxx node-es2
tk-search-module r STARTED .4kb .yyy.yy.yyy node-es1
tk-search-module p STARTED 159b .xxx.xx.xxx node-es2
tk-search-module r STARTED 159b .yyy.yy.yyy node-es1
tk-search p STARTED .5mb .xxx.xx.xxx node-es2
tk-search r STARTED .8mb .yyy.yy.yyy node-es1
tk-search r STARTED .5mb .xxx.xx.xxx node-es2
tk-search p STARTED .5mb .yyy.yy.yyy node-es1
tk-search r STARTED .6mb .xxx.xx.xxx node-es2
tk-search p STARTED .3mb .yyy.yy.yyy node-es1
tk-search p STARTED .5mb .xxx.xx.xxx node-es2
tk-search r STARTED 45mb .yyy.yy.yyy node-es1
tk-search p STARTED .7mb .xxx.xx.xxx node-es2
tk-search r STARTED .8mb .yyy.yy.yyy node-es1

15. segments指令

该指令反应的是在当前index中的某个shard的segment的信息,属于相对底层的信息。

 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/segments?v
index shard prirep ip segment generation docs.count docs.deleted size size.memory committed searchable version compound
tk-search-module p .xxx.xx.xxx _0 .2kb true true 5.5. true
tk-search-module r .yyy.yy.yyy _0 .2kb true true 5.5. true
tk-search p .xxx.xx.xxx _1bd .9mb true true 5.5. false
tk-search p .xxx.xx.xxx _1ft .7mb true true 5.5. false
tk-search p .xxx.xx.xxx _1jz .6mb true true 5.5. false
tk-search p .xxx.xx.xxx _1kt .2mb true true 5.5. true
tk-search p .xxx.xx.xxx _1ku .6kb true true 5.5. true
tk-search p .xxx.xx.xxx _1kv .3kb true true 5.5. true
tk-search p .xxx.xx.xxx _1kw .1kb true true 5.5. true
tk-search r .yyy.yy.yyy _1bm .8mb true true 5.5. false
tk-search r .yyy.yy.yyy _1g2 .3mb true true 5.5. false
tk-search r .yyy.yy.yyy _1ki .2mb true true 5.5. true
tk-search r .yyy.yy.yyy _1ks .7kb true true 5.5. true
tk-search r .yyy.yy.yyy _1kt .2mb true true 5.5. true
tk-search r .yyy.yy.yyy _1ku .9kb true true 5.5. true
tk-search r .yyy.yy.yyy _1kv .8kb true true 5.5. true
tk-search r .xxx.xx.xxx _189 .8mb true true 5.5. false
tk-search r .xxx.xx.xxx _1ed .2mb true true 5.5. false
tk-search r .xxx.xx.xxx _1jd .1mb true true 5.5. false
tk-search r .xxx.xx.xxx _1kr .8mb true true 5.5. true
tk-search r .xxx.xx.xxx _1ks .3kb true true 5.5. true
tk-search r .xxx.xx.xxx _1kt .1kb true true 5.5. true
tk-search r .xxx.xx.xxx _1ku .9kb true true 5.5. true
tk-search r .xxx.xx.xxx _1kv .4kb true true 5.5. true
tk-search r .xxx.xx.xxx _1kw 129kb true true 5.5. true
tk-search r .xxx.xx.xxx _1kx .1kb true true 5.5. true
tk-search p .yyy.yy.yyy _193 .9mb true true 5.5. false
tk-search p .yyy.yy.yyy _1ee .2mb true true 5.5. false
tk-search p .yyy.yy.yyy _1jn .4mb true true 5.5. false
tk-search p .yyy.yy.yyy _1kr .5mb true true 5.5. true
tk-search p .yyy.yy.yyy _1ks .1kb true true 5.5. true
tk-search p .xxx.xx.xxx _1ar .8mb true true 5.5. false
tk-search p .xxx.xx.xxx _1fh .1mb true true 5.5. false
tk-search p .xxx.xx.xxx _1ki .5mb true true 5.5. false
tk-search p .xxx.xx.xxx _1kr .8mb true true 5.5. false
tk-search p .xxx.xx.xxx _1ks .3kb true true 5.5. true
tk-search p .xxx.xx.xxx _1kt .9kb true true 5.5. true
tk-search p .xxx.xx.xxx _1ku .1kb true true 5.5. true
tk-search r .yyy.yy.yyy _1kl .7kb true true 5.5. true
tk-search r .yyy.yy.yyy _1km .4kb true true 5.5. true
tk-search r .yyy.yy.yyy _1kn .3kb true true 5.5. true
tk-search r .yyy.yy.yyy _1kr .8mb true true 5.5. false
tk-search r .yyy.yy.yyy _1ks .9kb true true 5.5. true
tk-search r .yyy.yy.yyy _1kt .1kb true true 5.5. true
tk-search r .xxx.xx.xxx _1a7 .5mb true true 5.5. false
tk-search r .xxx.xx.xxx _1ex .9mb true true 5.5. false
tk-search r .xxx.xx.xxx _1jd .7mb true true 5.5. false
tk-search r .xxx.xx.xxx _1kr .2mb true true 5.5. true
tk-search r .xxx.xx.xxx _1ks .4kb true true 5.5. true
tk-search r .xxx.xx.xxx _1kt .4kb true true 5.5. true
tk-search p .yyy.yy.yyy _1c5 .3mb true true 5.5. false
tk-search p .yyy.yy.yyy _1gl .4mb true true 5.5. false
tk-search p .yyy.yy.yyy _1kh .5mb true true 5.5. true
tk-search p .yyy.yy.yyy _1kr 4mb true true 5.5. true
tk-search p .yyy.yy.yyy _1ks .9kb true true 5.5. true
tk-search p .yyy.yy.yyy _1kt .6kb true true 5.5. true
tk-search p .xxx.xx.xxx _17p 21mb true true 5.5. false
tk-search p .xxx.xx.xxx _1i0 .5mb true true 5.5. false
tk-search p .xxx.xx.xxx _1ki .4mb true true 5.5. true
tk-search p .xxx.xx.xxx _1kr 3mb true true 5.5. true
tk-search p .xxx.xx.xxx _1ks .8kb true true 5.5. true
tk-search p .xxx.xx.xxx _1kt .8kb true true 5.5. true
tk-search p .xxx.xx.xxx _1ku .5kb true true 5.5. true
tk-search p .xxx.xx.xxx _1kv .5kb true true 5.5. true
tk-search p .xxx.xx.xxx _1kw .8kb true true 5.5. true
tk-search p .xxx.xx.xxx _1kx .8kb true true 5.5. true
tk-search r .yyy.yy.yyy _1c5 .3mb true true 5.5. false
tk-search r .yyy.yy.yyy _1hf 10mb true true 5.5. false
tk-search r .yyy.yy.yyy _1kh .1mb true true 5.5. true
tk-search r .yyy.yy.yyy _1kr .6kb true true 5.5. true
tk-search r .yyy.yy.yyy _1ks .1mb true true 5.5. true
tk-search r .yyy.yy.yyy _1kt .8kb true true 5.5. true

上述的cat指令,相当于一个简单的memo,方便用来查看系统状态和数据分布。

上一篇:.net core 中的 DependencyInjection - IOC


下一篇:Java中查找文件并且打印输出指定文件下面的子目录