本博文讲述的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指令的帮助提示,如下:
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat #此指令与curl http://localhost:9200/_cat?help得到的结果一样 2 =^.^= 3 /_cat/allocation 4 /_cat/shards 5 /_cat/shards/{index} 6 /_cat/master 7 /_cat/nodes 8 /_cat/indices 9 /_cat/indices/{index} 10 /_cat/segments 11 /_cat/segments/{index} 12 /_cat/count 13 /_cat/count/{index} 14 /_cat/recovery 15 /_cat/recovery/{index} 16 /_cat/health 17 /_cat/pending_tasks 18 /_cat/aliases 19 /_cat/aliases/{alias} 20 /_cat/thread_pool 21 /_cat/plugins 22 /_cat/fielddata 23 /_cat/fielddata/{fields} 24 /_cat/nodeattrs 25 /_cat/repositories 26 /_cat/snapshots/{repository}
2. aliases指令
aliases指令可以查询出当前索引的filter以及routing所配置的别名信息。
1 [root@localhost ~]# curl http://10.90.7.2:9201/_cat/aliases?v 2 alias index filter routing.index routing.search
上例中,表示我的系统中,没有配置任何的别名,这个在实际生产中,用的不是很多。
3. allocation指令
该指令提供一个快照,反映当前节点有多少个分片(shard)以及用了多少磁盘空间(disk)。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/allocation?v 2 shards disk.indices disk.used disk.avail disk.total disk.percent host ip node 3 10 295.7mb 4.4gb 44.6gb 49gb 9 10.xxx.xx.xxx 10.xxx.xx.xxx node-es1 4 10 311.1mb 4.4gb 44.6gb 49gb 9 10.xxx.xx.xxx 10.xxx.xx.xxx node-es2
4. count指令
该指令可以获取当前集群中有多少个document,类似mysql中有多少条记录,也可以获取指定index的document的数量。
1 [root@localhost ~]# curl http://10.90.7.2:9201/_cat/indices?v #获取当前系统有多少个index 2 health status index pri rep docs.count docs.deleted store.size pri.store.size 3 yellow open megacorp 5 1 0 0 795b 795b 4 yellow open tkssearch 5 1 1 0 18.2kb 18.2kb 5 yellow open test 5 1 1 0 4.2kb 4.2kb 6 yellow open tk-search11 5 1 2 0 25.2kb 25.2kb 7 yellow open cms 5 1 2 0 7.1kb 7.1kb 8 yellow open tksearch 5 1 12 0 53.3kb 53.3kb 9 yellow open rest_index 5 1 3 0 11.5kb 11.5kb 10 yellow open 3 5 1 0 0 795b 795b 11 yellow open 2 5 1 0 0 795b 795b 12 yellow open 1 5 1 0 0 795b 795b 13 yellow open indexdemo 5 1 5 0 19.2kb 19.2kb 14 yellow open indexdemo—— 5 1 0 0 795b 795b 15 yellow open tk-search-module 5 1 1 0 73.6kb 73.6kb 16 yellow open 5 5 1 0 0 795b 795b 17 yellow open 4 5 1 0 0 795b 795b 18 yellow open tksearch1 5 1 4 0 12.5kb 12.5kb 19 yellow open tk-search 5 1 5293 228 31.2mb 31.2mb
1 [root@localhost ~]# curl http://10.90.7.2:9201/_cat/count?v #获取当前集群中有多少个document 2 epoch timestamp count 3 1482461588 02:53:08 5324
1 [root@localhost ~]# curl http://10.90.7.2:9201/_cat/count/tksearch?v #获取tksearch这个index的document数量 2 epoch timestamp count 3 1482461711 02:55:11 12
5. health指令
该指令反应当前集群的健康指数信息。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/health?v 2 epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent 3 1482461665 10:54:25 tksearch green 2 2 20 10 0 0 0 0 - 100.0%
6. indices指令,master指令,上面的例子中有所反应,不再举例。
7. nodeattrs指令
该指令可以反应出当前数据节点的属性信息。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/nodeattrs?v 2 node host ip attr value
注:这里查不到数据,没有弄明白,官网的说明中,有结果,是什么地方配置的问题?
8. node指令
该指令反应出当前集群的拓扑信息。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://10.130.203.111:9200/_cat/nodes?v 2 host ip heap.percent ram.percent load node.role master name 3 10.xxx.xx.xxx 10.xxx.xx.xxx 16 44 0.00 d m node-es1 4 10.yyy.yy.yyy 10.yyy.yy.yyy 8 43 0.00 d * node-es2
9. pending_tasks指令
该指令反应当前集群有多少任务处在pending状态,与指令/_cluster/pending_tasks的效果一样。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/pending_tasks?v 2 insertOrder timeInQueue priority source
上例说明没有处在pending状态的任务。
10. plugins指令
该指令提供一个视图,反应当前节点中处在运行状态的插件。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/plugins?v 2 name component version type url
11. recovery指令
该指令反应当前系统中,索引分片的恢复信息,包括正在进行的以及已经完成了的。恢复,指的是当节点添加或者减少时发生的数据移动造成的。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/recovery?v 2 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 3 tk-search-module 0 15 store done 10.xxx.xx.xxx 10.xxx.xx.xxx n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 4 tk-search-module 0 594 replica done 10.xxx.xx.xxx 10.yyy.yy.yyy n/a n/a 1 100.0% 130 100.0% 1 130 0 100.0% 0 5 tk-search-module 1 59 replica done 10.yyy.yy.yyy 10.xxx.xx.xxx n/a n/a 1 100.0% 130 100.0% 1 130 0 100.0% 0 6 tk-search-module 1 10 store done 10.yyy.yy.yyy 10.yyy.yy.yyy n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 7 tk-search-module 2 7 store done 10.xxx.xx.xxx 10.xxx.xx.xxx n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 8 tk-search-module 2 645 replica done 10.xxx.xx.xxx 10.yyy.yy.yyy n/a n/a 1 100.0% 130 100.0% 1 130 1 100.0% 1 9 tk-search-module 3 43 replica done 10.yyy.yy.yyy 10.xxx.xx.xxx n/a n/a 1 100.0% 130 100.0% 1 130 0 100.0% 0 10 tk-search-module 3 8 store done 10.yyy.yy.yyy 10.yyy.yy.yyy n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 11 tk-search-module 4 22 store done 10.xxx.xx.xxx 10.xxx.xx.xxx n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 12 tk-search-module 4 533 replica done 10.xxx.xx.xxx 10.yyy.yy.yyy n/a n/a 1 100.0% 130 100.0% 1 130 0 100.0% 0 13 tk-search 0 10 store done 10.xxx.xx.xxx 10.xxx.xx.xxx n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 14 tk-search 0 533 replica done 10.xxx.xx.xxx 10.yyy.yy.yyy n/a n/a 1 100.0% 130 100.0% 1 130 0 100.0% 0 15 tk-search 1 46 replica done 10.yyy.yy.yyy 10.xxx.xx.xxx n/a n/a 1 100.0% 130 100.0% 1 130 0 100.0% 0 16 tk-search 1 25 store done 10.yyy.yy.yyy 10.yyy.yy.yyy n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 17 tk-search 2 13 store done 10.xxx.xx.xxx 10.xxx.xx.xxx n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 18 tk-search 2 587 replica done 10.xxx.xx.xxx 10.yyy.yy.yyy n/a n/a 1 100.0% 130 100.0% 1 130 1 100.0% 1 19 tk-search 3 28 replica done 10.yyy.yy.yyy 10.xxx.xx.xxx n/a n/a 1 100.0% 130 100.0% 1 130 0 100.0% 0 20 tk-search 3 31 store done 10.yyy.yy.yyy 10.yyy.yy.yyy n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 21 tk-search 4 7 store done 10.xxx.xx.xxx 10.xxx.xx.xxx n/a n/a 0 0.0% 0 0.0% 0 0 0 100.0% 0 22 tk-search 4 536 replica done 10.xxx.xx.xxx 10.yyy.yy.yyy n/a n/a 1 100.0% 130 100.0% 1 130 0 100.0% 0
12. repositories指令
该指令反应当前集群中注册了多少个repository。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/repositories?v 2 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”
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/thread_pool?v 2 host ip bulk.active bulk.queue bulk.rejected index.active index.queue index.rejected search.active search.queue search.rejected 3 10.yyy.yy.yyy 10.yyy.yy.yyy 0 0 0 0 0 0 0 0 0 4 10.xxx.xx.xxx 10.xxx.xx.xxx 0 0 0 0 0 0 0 0 0
14. shards指令
该指令,相对比较重要,反应每个节点有那些分片,告诉我们,那些是主分片,那些是从分片,每个分片的document数量,以及在该节点占用的磁盘空间。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/shards?v 2 index shard prirep state docs store ip node 3 tk-search-module 4 p STARTED 0 159b 10.xxx.xx.xxx node-es2 4 tk-search-module 4 r STARTED 0 159b 10.yyy.yy.yyy node-es1 5 tk-search-module 3 r STARTED 0 159b 10.xxx.xx.xxx node-es2 6 tk-search-module 3 p STARTED 0 159b 10.yyy.yy.yyy node-es1 7 tk-search-module 1 r STARTED 0 159b 10.xxx.xx.xxx node-es2 8 tk-search-module 1 p STARTED 0 159b 10.yyy.yy.yyy node-es1 9 tk-search-module 2 p STARTED 1 79.4kb 10.xxx.xx.xxx node-es2 10 tk-search-module 2 r STARTED 1 79.4kb 10.yyy.yy.yyy node-es1 11 tk-search-module 0 p STARTED 0 159b 10.xxx.xx.xxx node-es2 12 tk-search-module 0 r STARTED 0 159b 10.yyy.yy.yyy node-es1 13 tk-search 4 p STARTED 10740 51.5mb 10.xxx.xx.xxx node-es2 14 tk-search 4 r STARTED 10740 61.8mb 10.yyy.yy.yyy node-es1 15 tk-search 3 r STARTED 10655 64.5mb 10.xxx.xx.xxx node-es2 16 tk-search 3 p STARTED 10655 60.5mb 10.yyy.yy.yyy node-es1 17 tk-search 1 r STARTED 10704 67.6mb 10.xxx.xx.xxx node-es2 18 tk-search 1 p STARTED 10704 66.3mb 10.yyy.yy.yyy node-es1 19 tk-search 2 p STARTED 10705 64.5mb 10.xxx.xx.xxx node-es2 20 tk-search 2 r STARTED 10705 45mb 10.yyy.yy.yyy node-es1 21 tk-search 0 p STARTED 10561 62.7mb 10.xxx.xx.xxx node-es2 22 tk-search 0 r STARTED 10561 61.8mb 10.yyy.yy.yyy node-es1
15. segments指令
该指令反应的是在当前index中的某个shard的segment的信息,属于相对底层的信息。
1 [elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/segments?v 2 index shard prirep ip segment generation docs.count docs.deleted size size.memory committed searchable version compound 3 tk-search-module 2 p 10.xxx.xx.xxx _0 0 1 0 79.2kb 3061 true true 5.5.2 true 4 tk-search-module 2 r 10.yyy.yy.yyy _0 0 1 0 79.2kb 3061 true true 5.5.2 true 5 tk-search 0 p 10.xxx.xx.xxx _1bd 1705 6248 4273 43.9mb 24975 true true 5.5.2 false 6 tk-search 0 p 10.xxx.xx.xxx _1ft 1865 1984 0 9.7mb 9274 true true 5.5.2 false 7 tk-search 0 p 10.xxx.xx.xxx _1jz 2015 1958 0 6.6mb 11137 true true 5.5.2 false 8 tk-search 0 p 10.xxx.xx.xxx _1kt 2045 348 0 2.2mb 9141 true true 5.5.2 true 9 tk-search 0 p 10.xxx.xx.xxx _1ku 2046 13 0 125.6kb 3323 true true 5.5.2 true 10 tk-search 0 p 10.xxx.xx.xxx _1kv 2047 1 0 13.3kb 2802 true true 5.5.2 true 11 tk-search 0 p 10.xxx.xx.xxx _1kw 2048 9 0 75.1kb 3371 true true 5.5.2 true 12 tk-search 0 r 10.yyy.yy.yyy _1bm 1714 6427 4105 43.8mb 24896 true true 5.5.2 false 13 tk-search 0 r 10.yyy.yy.yyy _1g2 1874 1963 0 9.3mb 9474 true true 5.5.2 false 14 tk-search 0 r 10.yyy.yy.yyy _1ki 2034 1028 0 4.2mb 9721 true true 5.5.2 true 15 tk-search 0 r 10.yyy.yy.yyy _1ks 2044 3 0 37.7kb 3020 true true 5.5.2 true 16 tk-search 0 r 10.yyy.yy.yyy _1kt 2045 1131 0 4.2mb 9681 true true 5.5.2 true 17 tk-search 0 r 10.yyy.yy.yyy _1ku 2046 6 0 49.9kb 3156 true true 5.5.2 true 18 tk-search 0 r 10.yyy.yy.yyy _1kv 2047 3 0 35.8kb 3063 true true 5.5.2 true 19 tk-search 1 r 10.xxx.xx.xxx _189 1593 5003 5676 44.8mb 26155 true true 5.5.2 false 20 tk-search 1 r 10.xxx.xx.xxx _1ed 1813 2624 0 11.2mb 9764 true true 5.5.2 false 21 tk-search 1 r 10.xxx.xx.xxx _1jd 1993 2388 0 8.1mb 11006 true true 5.5.2 false 22 tk-search 1 r 10.xxx.xx.xxx _1kr 2043 599 0 2.8mb 10310 true true 5.5.2 true 23 tk-search 1 r 10.xxx.xx.xxx _1ks 2044 8 0 43.3kb 3146 true true 5.5.2 true 24 tk-search 1 r 10.xxx.xx.xxx _1kt 2045 7 0 60.1kb 3168 true true 5.5.2 true 25 tk-search 1 r 10.xxx.xx.xxx _1ku 2046 19 0 102.9kb 3328 true true 5.5.2 true 26 tk-search 1 r 10.xxx.xx.xxx _1kv 2047 26 0 131.4kb 3256 true true 5.5.2 true 27 tk-search 1 r 10.xxx.xx.xxx _1kw 2048 20 0 129kb 3347 true true 5.5.2 true 28 tk-search 1 r 10.xxx.xx.xxx _1kx 2049 10 0 68.1kb 3368 true true 5.5.2 true 29 tk-search 1 p 10.yyy.yy.yyy _193 1623 5413 5273 44.9mb 26169 true true 5.5.2 false 30 tk-search 1 p 10.yyy.yy.yyy _1ee 1814 2265 0 10.2mb 9257 true true 5.5.2 false 31 tk-search 1 p 10.yyy.yy.yyy _1jn 2003 2544 0 8.4mb 11517 true true 5.5.2 false 32 tk-search 1 p 10.yyy.yy.yyy _1kr 2043 472 0 2.5mb 9466 true true 5.5.2 true 33 tk-search 1 p 10.yyy.yy.yyy _1ks 2044 10 0 68.1kb 3368 true true 5.5.2 true 34 tk-search 2 p 10.xxx.xx.xxx _1ar 1683 6097 4593 44.8mb 25864 true true 5.5.2 false 35 tk-search 2 p 10.xxx.xx.xxx _1fh 1853 2102 0 10.1mb 9360 true true 5.5.2 false 36 tk-search 2 p 10.xxx.xx.xxx _1ki 2034 1201 0 4.5mb 10397 true true 5.5.2 false 37 tk-search 2 p 10.xxx.xx.xxx _1kr 2043 1287 0 4.8mb 10632 true true 5.5.2 false 38 tk-search 2 p 10.xxx.xx.xxx _1ks 2044 16 0 102.3kb 3243 true true 5.5.2 true 39 tk-search 2 p 10.xxx.xx.xxx _1kt 2045 1 0 20.9kb 2880 true true 5.5.2 true 40 tk-search 2 p 10.xxx.xx.xxx _1ku 2046 1 0 14.1kb 2748 true true 5.5.2 true 41 tk-search 2 r 10.yyy.yy.yyy _1kl 2037 5 0 51.7kb 3188 true true 5.5.2 true 42 tk-search 2 r 10.yyy.yy.yyy _1km 2038 7 0 48.4kb 3132 true true 5.5.2 true 43 tk-search 2 r 10.yyy.yy.yyy _1kn 2039 6 0 34.3kb 3052 true true 5.5.2 true 44 tk-search 2 r 10.yyy.yy.yyy _1kr 2043 10678 9 44.8mb 25566 true true 5.5.2 false 45 tk-search 2 r 10.yyy.yy.yyy _1ks 2044 8 0 66.9kb 3135 true true 5.5.2 true 46 tk-search 2 r 10.yyy.yy.yyy _1kt 2045 1 0 14.1kb 2748 true true 5.5.2 true 47 tk-search 3 r 10.xxx.xx.xxx _1a7 1663 5877 4759 44.5mb 25972 true true 5.5.2 false 48 tk-search 3 r 10.xxx.xx.xxx _1ex 1833 2053 0 9.9mb 9164 true true 5.5.2 false 49 tk-search 3 r 10.xxx.xx.xxx _1jd 1993 2066 0 6.7mb 10598 true true 5.5.2 false 50 tk-search 3 r 10.xxx.xx.xxx _1kr 2043 657 0 3.2mb 10707 true true 5.5.2 true 51 tk-search 3 r 10.xxx.xx.xxx _1ks 2044 1 0 16.4kb 2808 true true 5.5.2 true 52 tk-search 3 r 10.xxx.xx.xxx _1kt 2045 1 0 13.4kb 2802 true true 5.5.2 true 53 tk-search 3 p 10.yyy.yy.yyy _1c5 1733 6734 3896 44.3mb 25822 true true 5.5.2 false 54 tk-search 3 p 10.yyy.yy.yyy _1gl 1893 1977 0 8.4mb 8786 true true 5.5.2 false 55 tk-search 3 p 10.yyy.yy.yyy _1kh 2033 882 0 3.5mb 9236 true true 5.5.2 true 56 tk-search 3 p 10.yyy.yy.yyy _1kr 2043 1047 0 4mb 9878 true true 5.5.2 true 57 tk-search 3 p 10.yyy.yy.yyy _1ks 2044 13 0 89.9kb 3263 true true 5.5.2 true 58 tk-search 3 p 10.yyy.yy.yyy _1kt 2045 2 0 23.6kb 2949 true true 5.5.2 true 59 tk-search 4 p 10.xxx.xx.xxx _17p 1573 4615 3 21mb 17758 true true 5.5.2 false 60 tk-search 4 p 10.xxx.xx.xxx _1i0 1944 4783 1323 24.5mb 16636 true true 5.5.2 false 61 tk-search 4 p 10.xxx.xx.xxx _1ki 2034 620 0 2.4mb 8300 true true 5.5.2 true 62 tk-search 4 p 10.xxx.xx.xxx _1kr 2043 645 0 3mb 8849 true true 5.5.2 true 63 tk-search 4 p 10.xxx.xx.xxx _1ks 2044 17 0 95.8kb 3418 true true 5.5.2 true 64 tk-search 4 p 10.xxx.xx.xxx _1kt 2045 15 0 103.8kb 3408 true true 5.5.2 true 65 tk-search 4 p 10.xxx.xx.xxx _1ku 2046 20 0 101.5kb 3206 true true 5.5.2 true 66 tk-search 4 p 10.xxx.xx.xxx _1kv 2047 21 0 133.5kb 3314 true true 5.5.2 true 67 tk-search 4 p 10.xxx.xx.xxx _1kw 2048 1 0 14.8kb 2838 true true 5.5.2 true 68 tk-search 4 p 10.xxx.xx.xxx _1kx 2049 3 0 27.8kb 2956 true true 5.5.2 true 69 tk-search 4 r 10.yyy.yy.yyy _1c5 1733 6839 3873 45.3mb 26305 true true 5.5.2 false 70 tk-search 4 r 10.yyy.yy.yyy _1hf 1923 2370 0 10mb 10407 true true 5.5.2 false 71 tk-search 4 r 10.yyy.yy.yyy _1kh 2033 759 0 3.1mb 9270 true true 5.5.2 true 72 tk-search 4 r 10.yyy.yy.yyy _1kr 2043 20 0 129.6kb 3305 true true 5.5.2 true 73 tk-search 4 r 10.yyy.yy.yyy _1ks 2044 749 0 3.1mb 9171 true true 5.5.2 true 74 tk-search 4 r 10.yyy.yy.yyy _1kt 2045 3 0 27.8kb 2956 true true 5.5.2 true
上述的cat指令,相当于一个简单的memo,方便用来查看系统状态和数据分布。