用jmeter编写脚本做实时线上监控
将失败的请求存入xml格式的文件中
选择想要的信息,信息太多是无用的,处理也不方便
#!/bin/bash # 文件路径 dir="/opt/monitorScript/mtl_pc.jmx" # jmter路径 jmterdir="/opt/jmeter5.1.1" ## 日志存储地址 log="/tmp" ## 设置时间 time=`date +%Y%m%d%H%M%S` ## 设置操作函数 function operate(){ /opt/jmeter5.1.1/bin/jmeter.sh -n -t $dir>>/tmp/mtl.log } ## 判断xml日志文件是否存在,不存在, if [ -f $log/mtl_pc.xml ];then mv $log/mtl_pc.xml $log/mtl_pc_$time.xml operate else operate fi ## 定义接口名称 lb=`cat $log/mtl_pc.xml |xml2|grep "@lb"|awk -F "=" ‘{print $2}‘|tail -1` ## 获取接口地址 URL=`cat $log/mtl_pc.xml|xml2|grep "java.net.URL" |tail -1` url=`echo ${URL#*=}` ## 获取异常信息 failureMessage=`cat $log/mtl_pc.xml|xml2|grep "failureMessage"|awk -F ‘=‘ ‘{print $2}‘|sed "s/‘//g"|tail -2` ## failureMessagenum=`cat $log/mtl_pc.xml|xml2|grep "failureMessage"|wc -l` ## 设置函数,发送钉钉群 function SendMessageToDingding(){ Dingding_Url="https://oapi.dingtalk.com/robot/send?access_token=8ba7c120854ac253d7affa1f0b10e1e34aa5ad3ccd467694148533797f471ec9" curl "${Dingding_Url}" -H ‘Content-Type: application/json‘ -d "{ ‘msgtype‘: ‘text‘, ‘text‘: { ‘content‘: ‘接口场景:摩天轮线上业务监控\n接口名称:$lb\n接口地址:$url\n接口异常:$failureMessage\n‘ } }" } if [ $failureMessagenum -ge 3 ];then SendMessageToDingding else echo "成功" fi ~
相关推荐
与卿画眉共浮生 2020-10-14
xiyang 2020-08-21
baijinswpu 2020-07-29
leonranri 2020-07-26
zhongliwen 2020-07-05
麋鹿麋鹿迷了路 2020-07-05
zengyu00 2020-07-05
XGQ 2020-07-04
CoderBoy 2020-06-28
whbing 2020-06-28
绝望的乐园 2020-06-27
wellfly 2020-06-26
菇星獨行 2020-06-25
草原孤狼 2020-06-25
坚持着执着 2020-06-16
wcqwcq 2020-06-14
yuanye0 2020-06-14
zhongliwen 2020-06-13
MrFuWen 2020-06-09