客户请求截图系统返回状态码检查

统计httpcode 200所占比例,并记录请求流名对应返回状态码进行后续排查,此处不发告警

  • 获取在线流数据源格式
cat /tmp/xylive-a-upload.kascend.com_upstream.log
{"data":{"xylive-a-upload.kascend.com":[{"app":"chushou_rookie","stream":"739d5dbd864840aa8d18dd2b94492b42"},{"app":"chushou_rookie","stream":"ca452b077cb94746ab6492de2a40d93f"},{"app":"chushou_rookie","stream":"e8f1f1117448412f99f5ba28131016ca"},{"app":"chushou_rookie","stream":"7be9dfd873f842de91d0a5e331fa65cd"},{"app":"chushou_rookie","stream":"7e6b4036adb14bf9888a05ea52644d68"},{"app":"chushou_rookie","stream":"aebb6ed025e84a30af0f3e00a713362e"},{"app":"chushou_rookie","stream":"4cf824b920aa41be81810b0b828d7600"},{"app":"chushou_rookie","stream":"92a546324ed443ef8145dda7e73c5df4"},{"app":"chushou_rookie","stream":"696a1bb9f8ef43858300b85c0d22d36b"},{"app":"chushou_rookie","stream":"109d1d7a17b54e9ab4b16545332d3ff9"},{"app":"chushou_rookie","stream":"1f1f18ed869242a1b005f56cb6735879"},{"app":"chushou_rookie","stream":"285d4c4a93e3404ba14ab45256a70361"},{"app":"chushou_rookie","stream":"817912ce49b94039a96d4e5e390bb547"},{"app":"chushou_rookie","stream":"8e001a7558fd45109105f245c21ce2e7"},{"app":"chushou_rookie","stream":"9818ab8699ba4196b9c64b398fd7b9c0"},{"app":"chushou_rookie","stream":"664b0ed82943448cba0d7de57a22a996"},{"app":"chushou_rookie","stream":"4f0e88b8d776452fadb23f97871d4985"},{"app":"chushou_rookie","stream":"ee2fd08c3fa1408aaaf043d1a3580809"},{"app":"chushou_rookie","stream":"e6edbc7afa984beca073233fa52fa946"},{"app":"chushou_rookie","stream":"3504c5795e0e43db946a24b846ac94f4"},{"app":"chushou_rookie","stream":"5681ed6dde0049f093db2a5392a68350"},{"app":"chushou_rookie","stream":"5c317defb93c4d7799213fa44925015b"},{"app":"chushou_rookie","stream":"a793535875854fbabab265bed2c1de06"},{"app":"chushou_rookie","stream":"39f3fcb92dd543e184c4e6d83fcf703b"},{"app":"chushou_rookie","stream":"931f7389c1c1420697178ffaef155a88"}]},"count":474,"code":0,"message":""}
  • curl请求截图返回头部源格式
    HTTP/1.1 200 OK
    Server: openresty
    Date: Fri, 02 Jun 2017 02:45:41 GMT
    Content-Type: image/jpeg
    Content-Length: 92358
    Connection: keep-alive
    Snapshot-Last-Active: Mon, 29 May 2017 02:51:17 GMT
    Expires: Fri, 02 Jun 2017 02:45:40 GMT
    Cache-Control: no-cache    
  • 脚本内容
#!/bin/bash
timestamp=`date +%s`
user="kmanage"
action="Live.ActiveStream"
key="d683575969b52144f29da0efcf391454"
token=`echo -n "$action$user$key$timestamp"|md5sum|awk '{print $1}'`
Sign="$user-$timestamp-$token"
script=`basename $0`
#domain="xylive-a-upload.kascend.com"
#edge_ip="183.131.64.5"
usage() {
echo "Usage:$script arg1(edge_ip) arg2(domain) arg3(app) arg4(jietu app)"
exit 1
}

function check_customer_snapshot_httpcode() {
edge_ip=$1
domain=$2
app=$3
jietu_domain=$4
curl "http://mc-service.live.p2cdn.com/index.php?Action=$action&domain=$domain&Sign=$Sign" > /tmp/"$domain"_upstream.log 

cat /tmp/xylive-a-upload.kascend.com_upstream.log |json_reformat|grep "stream"|awk -F"[ :]*" '{print $3}'|tr -d '"'>/tmp/"$domain"_format_ups.log

awk '{print "curl -s --connect-timeout 3 -H \"Host:'${jietu_domain}'\" http://'${edge_ip}'/'${jietu_domain}'/'$app'/"$1".jpg --head"}' </tmp/"$domain"_format_ups.log|bash|grep -E "HTTP|Snapshot-Last-Active" >/tmp/snapshot_req_temp.log

awk '{tmp1=$0;getline;print tmp1" "$0}' /tmp/snapshot_req_temp.log |tr -d '\r' >/tmp/snapshot_request_.log

paste /tmp/"$domain"_format_ups.log /tmp/snapshot_request_.log >/tmp/"$domain"_result.log

httpcode_200_percent=$(awk '{S[$3]++}END{for(httpcode in S) print httpcode,S[httpcode]}' /tmp/"$domain"_result.log|awk '{if($1=="200") tmp=$2;sum+=$2}END{printf"%.3f\n",(tmp/sum)*100}')
if [ $(echo "${httpcode_200_percent}<99"|bc) -eq 1 ];then
        echo "customer snapshot httpcode 200 less than 99%"
#       alarm_customer_snapshot_httpcode200
fi
}

main () {

if [ $# -ne 4 ];then
        usage
fi

check_customer_snapshot_httpcode $1 $2 $3 $4

}

main "$@"
posted on 2017-05-27 17:10  平凡之路dd  阅读(444)  评论(0编辑  收藏  举报