首页 技术 正文
技术 2022年11月16日
0 收藏 992 点赞 3,775 浏览 1827 个字

轻量级监控平台之java进程监控脚本

#!/bin/bash
#进程监控脚本
#功能需求: 上报机器Java进程的进程ID,对应的端口号service tcp端口号,tomcat http 端口号,以及tcp链接数数据. /etc/profile
. ~/.bash_profilepushurl="https://lightmonitorapi.test.cn/push/process"
proNum=$(jps | grep -v Jps | cut -d' ' -f1)
i=1
cd /opt/web/
webDir=$( ls )
serviceRunning=$(service list | grep RUNNING)
msg=""for pid in $proNum
do
port=$(echo "$serviceRunning" | grep $pid | awk -F " " '{print $8}') if [ -n "$port" ];then serviceName=$(echo "$serviceRunning" | grep $pid | awk -F " " '{print $1}')
threadTime=$(ps -eo pid,tty,user,comm,stime,etime | grep "$pid"| cut -c 46-60)
tcpStatus=$(netstat -nat | grep $port | awk '{print $6}' | sort | uniq -c)
escount=$( echo "$tcpStatus" | grep "ESTABLISHED" | awk '{print $1}')
cwcount=$( echo "$tcpStatus" | grep "CLOSE_WAIT" | awk '{print $1}')
twcount=$( echo "$tcpStatus" | grep "TIME_WAIT" | awk '{print $1}')
licount=$( echo "$tcpStatus" | grep "LISTEN" | awk '{print $1}')
msg=$msg"$pid,$serviceName,$port,$threadTime,T,E$escount,C$cwcount,T$twcount,L$licount\n"
else
for fileName in $webDir
do
fileDir=$(ps -ef | grep "$pid" | grep "$fileName")
if [ -n "$fileDir" ];then
serverPath="/opt/web/$fileName/conf/server.xml"
threadTime=$(ps -eo pid,tty,user,comm,stime,etime | grep "$pid"| cut -c 46-60)
httpPort=$(cat "$serverPath" | grep 'Connector' | cut -d' ' -f6 | awk -F "[\"\"]" '{print $2}')
tcpStatus=$(netstat -nat | grep $httpPort | awk '{print $6}' | sort | uniq -c)
escount=$( echo "$tcpStatus" | grep "ESTABLISHED" | awk '{print $1}')
cwcount=$( echo "$tcpStatus" | grep "CLOSE_WAIT" | awk '{print $1}')
twcount=$( echo "$tcpStatus" | grep "TIME_WAIT" | awk '{print $1}')
licount=$( echo "$tcpStatus" | grep "LISTEN" | awk '{print $1}') msg=$msg"$pid,$fileName,$httpPort,$threadTime,H,E$escount,C$cwcount,T$twcount,L$licount\n"
fi
done
fi
doneip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d '/')ticket=$(cat /opt/shell/ticket.txt)curl $pushurl \
-H "Accept: application/json" \
-H 'Content-Type: application/json' \
-d \ '{"ip": "'"${ip}"'", "ticket": "'"${ticket}"'", "data": "'"${msg}"'"}'
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,565
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905