当前位置:   article > 正文

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

写脚本 统计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=[09azAZ],.*/\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


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/300967
推荐阅读
相关标签
  

闽ICP备14008679号