美文网首页already
【shell】应用、端口、中间件shell检测脚本

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

作者: Bogon | 来源:发表于2022-04-14 00:03 被阅读0次

测端口 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

相关文章

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

    测端口 80 443 2022端口连通性 检查数据盘使用率 格式化输出rabbitMQ相关信息 查看 CPU 、内...

  • [Linux]Shell

    shell:命令解释器,驱动linux内核;应用程序调用shell命令 1.Shell脚本的执行方式 脚本格式要求...

  • 2018-09-26

    shell脚本 1.1、什么是shell脚本(shell script , ...

  • Shell入门笔记

    Shell脚本:Linux Shell脚本学习指南菜鸟教程 - Shell教程Linux入门 - Shell脚本是...

  • 嵌入式day12

    shell脚本的本质 shell脚本语言是解释型语言 shell脚本的本质:shell命令的有序集合 shell编...

  • 【生物信息笔记】shell 脚本 (dry-2)

    shell 和 shell script(脚本)区别: shell 和 shell 脚本是两个不同概念,shell...

  • Shell script + crontab实现Mysql定时备

    一、Shell 脚本 Shell 脚本(shell script),是一种为 shell 编写的脚本程序。 业界所...

  • Shell | 初识Shell 1

    一、初识Shell shell是一段应用程序,是用户与操作系统交互的桥梁 shell通常指shell脚本 shel...

  • shell图形化界面脚本实现

    1.基于架构/角色进行检测2.检测网络端口映射是否正常3.检测其进程/启动。 shell字符串拼接截取,shell...

  • shell脚本

    什么是shell脚本 Shell 脚本(shell script),是一种为 shell 编写的脚本程序。业界所说...

网友评论

    本文标题:【shell】应用、端口、中间件shell检测脚本

    本文链接:https://www.haomeiwen.com/subject/wopasrtx.html