zoukankan      html  css  js  c++  java
  • 轻量级监控平台之java进程监控脚本

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

    #!/bin/bash
    #进程监控脚本
    #功能需求: 上报机器Java进程的进程ID,对应的端口号service tcp端口号,tomcat http 端口号,以及tcp链接数数据
    
    . /etc/profile
    . ~/.bash_profile
    
    pushurl="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
    "
       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
    "
               fi
           done
       fi
    done
    
    ip=$(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}"'"}'
    
    
  • 相关阅读:
    测序分析软件-phred的安装
    测序分析软件-trimmomatic的记录
    linux-ubuntu下fastQC的安装及使用
    linux 下统计文本行数
    linux .gz文件 解压缩命令
    启用谷歌浏览器Adobe Flash Player
    「三代组装」使用Pilon对基因组进行polish
    用BUSCO来评估基因组完整性
    linux tar.gz 文件解压缩
    查看jobs详情
  • 原文地址:https://www.cnblogs.com/coderManFans/p/11905382.html
Copyright © 2011-2022 走看看