check_canal.sh查看canal状态

  sre

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

CURNUM=             #当前的性能参数

quota=
QUOTASTR=
log_path="/data/cycore/cypass_exchange/server/canal/logs/example"
FLAGE=
FLAGEPID=
port=
record="canal"

canal_json=

function gotErr(){
    if [ "1" -eq 3 ];then        echo "该进程已不存在"
    fi
    exit1
}

function isAlive(){
    FLAGEPID=`ss -lnpt "( sport == :port )"|tail -n 1|awk -F " " '{print6}'|awk -F ',' '{print 2}'`
    if [[ "FLAGEPID" == "" ]];then
        gotErr 3
    fi
    canal_json="'cpname':'canal','FLAGEPID':'FLAGEPID'"
}

function getCanalLogTime(){
    canal_log1=`cat /root/{record}.txt|sed "s/[^0-9\.]//g"`
    canal_log2=`cd log_path;cat example.log|tail -n 1|grep -o 'timestamp=[0-9]\+'|awk 'END {print}'|sed "s/[^0-9\.]//g"`
    echo "canal_log2" > /root/{record}.txt
    timestamp={canal_log1:0:10}
    if [ "{canal_log1}" = "" -o "{canal_log2}" = "" ];then
        CURNUM=0
    elif [ "{canal_log1}" = "{canal_log2}" ];then
        CURNUM=2
    else
        CURNUM=0
    fi
}

#依据传入的参数值来判断我们要监控的服务是什么
#然后通过各个函数获取到具体的值
#值之间的
function analysisStat(){
    getCanalLogTime
    parseFileds "canal_log"
}

#CURNUM            当前值
#WARNLIMIT         告警的上限
#ERRORLIMIT    异常的上限
#判断以上三个值并拼接结果字符串
function parseFileds(){
    canal_json="canal_json,'1':'CURNUM'"
}

function analysisResult(){
    canal_json="{canal_json}"
    canal_json=`echo {canal_json//\'/\"}`
    echocanal_json
}

#输出错误信息并且退出程序
function showHelp(){
    if [ "1" != "" ];then
        echo "请输入1"
    fi
    echo "check_canal.sh 可以监听本地的cpu的状态 参数如下"
    echo "check_canal.sh [-p <<port>> -l <<log_path>>]"
    echo "-l 表示canal日志路径"
    exit 1
}

while getopts "l:p:r:h" arg
do
    case arg in
        l)
            log_path=OPTARG
            ;;
        p)
            port=OPTARG
            ;;
        h)
            showHelp
            ;;
        ?)            showHelp
            ;;
    esac
done

if [[? == 1 ]];then
    showHelp "正确参数"
fi


#插件正题部分 
#确定存活的
#启动
#分析
isAlive
analysisStat
analysisResult

LEAVE A COMMENT

Captcha Code