本博文講述的ES獲取系統數據的API是基於Elasticsearch 2.4.1版本的。node
0. overviewmysql
a. 下面將要介紹的全部的指令,都支持一個查詢參數v(verbose),用來顯示詳細的查詢結果。sql
b. cat的全部指令,都支持一個help參數查詢,幫助用戶瞭解cat相關指令都支持那些功能。curl
c. cat的全部指令,都支持一個h參數的查詢,指定指定的列信息進行輸出。url
例子: 查詢輸出master的ip以及node namespa
[elastic@t0-tkonline-cms-search01 ~]$ curl http://localhost:9200/_cat/master?h=ip,n插件
10.xxx.xx.xxx node-es2rest
1. help查詢參數code
下面,就以一個查看當前ES集羣master的信息的例子:component
[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,方便用來查看系統狀態和數據分佈。