Shell 脚本查看ElasticSearch

欢迎关注【无量测试之道】公众号,回复【领取资源】,
Python编程学习资源干货、
Python+Appium框架APP的UI自动化、
Python+Selenium框架Web的UI自动化、
Python+Unittest框架API自动化、

资源和代码 免费送啦~
文章下方有公众号二维码,可直接微信扫一扫关注即可。

今天的分享是关于如何使用Shell 脚本轻松搞定ES 的信息查询,通过不同的参数传入来获取相应的信息反馈。

相应的代码如下:

 1 #!/bin/bash
 2  
 3 username="admin"
 4 password="test123"
 5 ip=$2
 6  
 7 if [[ $1 == '' ]] #判断参数是否为空
 8 then
 9 echo "需要输入参数"
10 echo "$0 [ health | node | nodeprocess | disk | index | shards | status | task | fielddata | setting | backup ] hostip"
11 exit 0
12 fi
13  
14 case $1 in #匹配输出的参数
15 health)
16 echo "查看es集群状态"
17 curl -XGET -u${username}:${password} "http://${ip}:9200/_cluster/health?pretty"
18 ;;
19 node)
20 echo "查看节点信息"
21 curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/nodes?v"
22 ;;
23 nodeprocess)
24 echo "查看节点进程信息"
25 curl -XGET  -u${username}:${password} "http://${ip}:9200/_cat/nodes/process?pretty"
26 ;;
27 disk)
28 echo "查看各节点磁盘使用情况"
29 curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/allocation?v"
30 ;;
31 index)
32 echo "查看索引信息"
33 curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/indices?v"
34 ;;
35 shards)
36 echo "查看分片信息"
37 curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/shards?v"
38 ;;
39 status)
40 echo "查看状态信息"
41 curl -XGET -u${username}:${password} "http://${ip}:9200/_cluster/health?pretty"
42 ;;
43 task)
44 echo "查看执行队列"
45 curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/pending_tasks?v"
46 ;;
47 fielddata)
48 echo "查看数据结构"
49 curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/fielddata?v"
50 ;;
51 setting)
52 echo "查看配置信息"
53 curl -XGET -u${username}:${password} "http://${ip}:9200/_cluster/settings?pretty"
54 ;;
55 backup)
56 echo "查看备份信息"
57 curl -XGET -u${username}:${password} "http://${ip}:9200/_snapshot?pretty"
58 ;;
59 *)
60 echo "参数匹配不对,请参照如下输出:"
61 echo "$0 [ node | disk | index | shard | status | task | fielddata | setting | backup ] hostip"
62 exit 0
63 ;;
64 esac
65 exit 0

以上代码内容需耐心每一行一行的去分析理解才能对今天分享的内容有更深入的理解,如果对Shell 操作不熟悉的童鞋,可以参考之前分享的《Shell编程核心技术》系列文章。

备注:我的个人公众号已正式开通,致力于测试技术的分享,包含:大数据测试、功能测试,测试开发,API接口自动化、测试运维、UI自动化测试等,微信搜索公众号:“无量测试之道”,或扫描下方二维码:

 添加关注,让我们一起共同成长!

原文地址:https://www.cnblogs.com/Wu13241454771/p/13576288.html