discover_flume.sh感知flume

  sre

5f69949508f878875.jpg_fo742.png

#! /bin/bash
export LANG=en_US.UTF-8

pids=`ps aux | grep -v grep | grep -v ps.sh | grep org.apache.flume.node.Application | grep java | grep -v "uoamp" | awk '{print 2}'`
discover_flume_json=""

for pid inpids
do
    port=`netstat -lnp | grep pid/java | grep tcp | grep -v "127.0.0.1" | awk '{print4}'|awk -F ':' '{print NF}'`
    psinfo=`ps aux | greppid|grep java|grep -v ps|grep -v grep`
    config_path=`echo psinfo|awk -F ' ' '{for(i=1;i<NF;++i){if(index(i,"-cp")==1)print (i+1)}}'|awk -F ':' '{print1}'`
    if [ "port" != "" ];then
        discover_flume_json="discover_flume_json{'cpname':'flume','port':'port','path':'config_path','name':'Flume组件模板','flag':'pid'},"
    else
        discover_flume_json="discover_flume_json{'cpname':'flume','path':'config_path','name':'Flume组件模板','flag':'pid'},"
    fi
    #cd  config_path/../
done
result="[{discover_flume_json%,*}]"
result=`echo {result//\'/\"}`
echoresult

LEAVE A COMMENT

Captcha Code