一个统计日志中app访问云调用次数的脚本

#!/bin/sh

log_path=/root/test

appids_y_m_d_h_m=()
declare -A map=()

year=`date +%Y`
month=`date +%m`
#day=`date +%d`
day='13'
hour=`date +%H`
#min=`date +%M`
min='13'


#业务列表
dir_list=(iat tts)

for dir in ${dir_list[*]}
do
    cd ${log_path}/$dir/$year/$month/$day
    for hour_dir in `ls  .`
    do
        #echo $hour_dir
        cd $hour_dir
        for min_dir in `ls  .`
        do
            #echo $min_dir
            cd $min_dir
            for log_file in `ls  .`
            do
                flag="false"
                #统计每个日志文件
                while read line
                do
                    enter_cnt=`echo $line | grep '_inst::deal_request | enter' | wc -l`
                    appid_cnt=`echo $line | grep 'appid=' | wc -l`
                     
                    #echo $enter_cnt---$appid_cnt

                    
                    if [ "$enter_cnt" = "1"  ]
                    then
                        flag="true"
                    fi

                    #出现enter
                    if [ "$flag" = "true" ]
                    then
                        #appid出现
                        if [ "$appid_cnt" = "1" ]
                        then
                            flag='false'
                            #记录appid次数
                            appid=`echo $line | sed -n 's/.*,appid=\([0-9a-zA-Z]*\),.*/\1/pg'`
                            #echo $appid
                            key=${appid}_${year}_${month}_${day}_${hour}_${min}
                            echo $key
                            if [ map['$key'] = "" ]
                            then
                                map['$key']=1
                            else
                                ((map['$key']=map["$key"]+1))
                            fi

                        fi
                    fi
                done < $log_file

                printf "|%10s|%10s|%10s|%10s|%10s|%10s|%10s|\n" "appid" "year" "month" "day" "hour" "min" "count"
                for key in ${!map[@]}
                do
                    echo $key | awk -F'_' '{for(i=1;i<=NF;++i){printf "|%10s",$i}}'
                    printf "|%10s|\n" ${map[$key]}
                done
            done
        done
    done
done

exit


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值