already

【shell】应用、端口、中间件shell检测脚本

2022-04-14  本文已影响0人  Bogon

测端口 80 443 2022端口连通性

yum  -y install telnet
echo ""  |  telnet  www.example.com  80      2> /dev/null | grep -wq "Escape character is '^]'"
echo ""  |  telnet  www.example.com  443    2> /dev/null | grep -wq "Escape character is '^]'"
echo ""  |  telnet  www.example.com  2022  2> /dev/null | grep -wq "Escape character is '^]'"  && echo success

检查数据盘使用率

ansible -i hosts all -m shell -a "echo '======== 根分区 / 使用率 ========' ;df -hT| grep -w '/' | awk '{print \$6}'"
ansible -i hosts all -m shell -a "echo '======== /opt 使用率 ========' ;df -hT| grep '/opt' | awk '{print \$6}'"

格式化输出rabbitMQ相关信息

rabbitmqctl  list_policies  | awk '{printf "%-8s %-8s %-8s %-8s %-8s %-8s \n",$1,$2,$3,$4,$5,$6}'

rabbitmqctl list_exchanges name type durable auto_delete | grep -v "Listing exchanges ..." | awk 'BEGIN{printf "%-45s %-30s %-30s %-30s\n","name","type","durable","auto_delete"} {printf "%-45s %-30s %-30s %-30s\n",$1,$2,$3,$4}'

rabbitmqctl list_queues name durable auto_delete | grep -v "Listing queues ..." | awk 'BEGIN{printf "%-60s %-30s %-30s\n","name","durable","auto_delete"} {printf "%-60s %-30s %-30s\n",$1,$2,$3}'

rabbitmqctl  list_bindings | awk  '{printf "%-40s %-40s %-40s %-20s %-20s %-20s \n",$1,$2,$3,$4,$5,$6}' 

rabbitmqctl  list_connections | awk '{printf "%-10s %-20s %-10s %-10s\n",$1,$2,$3,$4}'

rabbitmqctl  list_channels  | awk '{printf "%-40s %-10s %-10s %-10s\n",$1,$2,$3,$4}'

rabbitmqctl  list_consumers status  | awk '{printf "%-40s %-40s %-40s %-20s %-20s %-20s \n",$1,$2,$3,$4,$5,$6}'

rabbitmqctl cluster_status

查看 CPU 、内存负载

top -b -n 1 | head -n 21

查看磁盘io

iostat -x 2 5
vmstat 1 15

查看nginx连接状态

sar -n EDEV 1 1
 ansible -i hosts  nginx -m shell -a  "/usr/sbin/ss -ant | awk '{++s[\$1]} END {for(k in s) print k,s[k]}'"

一键获取工程堆栈信息

 #!/bin/bash
ip="xx.xx.xx.xx"
service="iam"

echo "################ ${ip} ###################"

pid=$(ansible -i /path/to/hosts  ${ip}  -m shell -a  "ps aux | grep -w ${service} | grep  -v grep   | awk '{print \$2}'" | grep -v CHANGED)

ansible -i  /path/to/hosts  ${ip}  -m shell  --become -a  'su - test   -c   "jstack -l '${pid}' > /tmp/'${service}'-{{ inventory_hostname }}.txt"'

ansible -i  /path/to/hosts  ${ip}  -m  fetch -a 'src=/tmp/'${service}'-{{ inventory_hostname }}.txt dest=/tmp/ '
  1. top 找到CPU占用最高的pid

  2. top -Hp ${pid} 找到CPU占用最高的线程id记录一下

  3. jstack -l ${pid} > 工程名_jstack.txt 导出线程详情

  4. 分析(开发参与)根据线程id(转换为16进制),可以从工程名_jstack.txt定位到 具体代码行

  5. 将工程名_jstack.txt用可视化在线分析工具来分析 : https://heaphero.io/index.jsp

image.png
上一篇 下一篇

猜你喜欢

热点阅读