博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
分析rails日志,计算响应率
阅读量:6564 次
发布时间:2019-06-24

本文共 11515 字,大约阅读时间需要 38 分钟。

 

chmod +x analyse_log copy_log

 

(1)拷贝脚本到本地

脚本内容如下:

#!/usr/bin/env bashLOG_PATH=/opt/logsLOCAL_LOG_PATH=~/Documents/logs/8-15PROJECTS=(m-cms-for-tudou-tv m-cms-for-tv)if [[ $1 == "--debug" ]]; then  set -xfi# Create local directoriesfor project in ${projects[@]}; do  mkdir -p $SAVE_TO/$projectdone# Copy m-cms-for-tvproject=m-cms-for-tvremote_log_dir=$LOG_PATH/$projectfor server in {13..15}; do  for port in {5200..5207}; do    server_ip="10.xxx.32.$server"    local_log_dir=$LOCAL_LOG_PATH/$project/$server_ip    log_file="thin server (0.0.0.0:$port)_2015-08-15.log"    if [[ ! -e $local_log_dir/"$log_file" ]]; then      mkdir -p $local_log_dir      scp $server_ip:$remote_log_dir/"'$log_file'" $local_log_dir/$port.log    fi  donedone# Copy m-cms-for-todou-tvproject=m-cms-for-tudou-tvremote_log_dir=$LOG_PATH/$projectfor server in {13..15}; do  for port in {3201..3208}; do    server_ip="10.xxx.32.$server"    local_log_dir=$LOCAL_LOG_PATH/$project/$server_ip    log_file="thin server (0.0.0.0:$port)_2015-08-15.log"    if [[ ! -e $local_log_dir/"$log_file" ]]; then      mkdir -p $local_log_dir      scp $server_ip:$remote_log_dir/"'$log_file'" $local_log_dir/$port.log    fi  donedoneproject=ott-client-cmsremote_log_dir=/opt/app/ruby/$project/current/logfor server in {13..15}; do  server_ip="10.xxx.32.$server"  local_log_dir=$LOCAL_LOG_PATH/$project/$server_ip  log_file="nginx.access.20150815.log"  if [[ ! -e $local_log_dir/"$log_file" ]]; then    mkdir -p $local_log_dir    scp $server_ip:$remote_log_dir/$log_file $local_log_dir/$log_file  fidone

执行:

$./copy_log

执行后拷贝的日志如下

thin server (0.0.0.0:5200)_2015-08-15.log                                                                           100%   37MB   4.1MB/s   00:09    thin server (0.0.0.0:5201)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    thin server (0.0.0.0:5202)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    thin server (0.0.0.0:5203)_2015-08-15.log                                                                           100%   37MB   3.7MB/s   00:10    thin server (0.0.0.0:5204)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    thin server (0.0.0.0:5205)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    thin server (0.0.0.0:5206)_2015-08-15.log                                                                           100%   37MB   2.6MB/s   00:14    thin server (0.0.0.0:5207)_2015-08-15.log                                                                           100%   37MB   3.7MB/s   00:10    thin server (0.0.0.0:5200)_2015-08-15.log                                                                           100%   37MB   6.2MB/s   00:06    thin server (0.0.0.0:5201)_2015-08-15.log                                                                           100%   37MB   4.1MB/s   00:09    thin server (0.0.0.0:5202)_2015-08-15.log                                                                           100%   37MB   3.7MB/s   00:10    thin server (0.0.0.0:5203)_2015-08-15.log                                                                           100%   37MB   3.1MB/s   00:12    thin server (0.0.0.0:5204)_2015-08-15.log                                                                           100%   37MB   3.4MB/s   00:11    thin server (0.0.0.0:5205)_2015-08-15.log                                                                           100%   37MB   3.4MB/s   00:11    thin server (0.0.0.0:5206)_2015-08-15.log                                                                           100%   37MB   2.7MB/s   00:14    thin server (0.0.0.0:5207)_2015-08-15.log                                                                           100%   37MB   2.7MB/s   00:14    thin server (0.0.0.0:5200)_2015-08-15.log                                                                           100%   37MB   3.4MB/s   00:11    thin server (0.0.0.0:5201)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    thin server (0.0.0.0:5202)_2015-08-15.log                                                                           100%   37MB   4.6MB/s   00:08    thin server (0.0.0.0:5203)_2015-08-15.log                                                                           100%   37MB   6.2MB/s   00:06    thin server (0.0.0.0:5204)_2015-08-15.log                                                                           100%   37MB   3.1MB/s   00:12    thin server (0.0.0.0:5205)_2015-08-15.log                                                                           100%   37MB   3.4MB/s   00:11    thin server (0.0.0.0:5206)_2015-08-15.log                                                                           100%   37MB   4.7MB/s   00:08    thin server (0.0.0.0:5207)_2015-08-15.log                                                                           100%   37MB   3.7MB/s   00:10    thin server (0.0.0.0:3201)_2015-08-15.log                                                                           100%   64KB  63.7KB/s   00:00    thin server (0.0.0.0:3202)_2015-08-15.log                                                                           100%   63KB  63.2KB/s   00:00    thin server (0.0.0.0:3203)_2015-08-15.log                                                                           100%   69KB  68.9KB/s   00:00    thin server (0.0.0.0:3204)_2015-08-15.log                                                                           100%   67KB  66.9KB/s   00:00    thin server (0.0.0.0:3205)_2015-08-15.log                                                                           100%   55KB  55.5KB/s   00:00    thin server (0.0.0.0:3206)_2015-08-15.log                                                                           100%   63KB  63.0KB/s   00:00    thin server (0.0.0.0:3207)_2015-08-15.log                                                                           100%   57KB  56.7KB/s   00:00    thin server (0.0.0.0:3208)_2015-08-15.log                                                                           100%   60KB  60.4KB/s   00:00    scp: /opt/logs/m-cms-for-tudou-tv/thin server (0.0.0.0:3201)_2015-08-15.log: No such file or directorythin server (0.0.0.0:3202)_2015-08-15.log                                                                           100%   51KB  50.7KB/s   00:00    thin server (0.0.0.0:3203)_2015-08-15.log                                                                           100%   51KB  50.6KB/s   00:00    thin server (0.0.0.0:3204)_2015-08-15.log                                                                           100%   52KB  52.5KB/s   00:00    thin server (0.0.0.0:3205)_2015-08-15.log                                                                           100%   52KB  52.0KB/s   00:00    thin server (0.0.0.0:3206)_2015-08-15.log                                                                           100%   49KB  49.1KB/s   00:00    thin server (0.0.0.0:3207)_2015-08-15.log                                                                           100%   52KB  52.3KB/s   00:00    thin server (0.0.0.0:3208)_2015-08-15.log                                                                           100%   52KB  52.4KB/s   00:00    thin server (0.0.0.0:3201)_2015-08-15.log                                                                           100%   45KB  44.9KB/s   00:00    thin server (0.0.0.0:3202)_2015-08-15.log                                                                           100%   44KB  43.7KB/s   00:00    thin server (0.0.0.0:3203)_2015-08-15.log                                                                           100%   46KB  45.6KB/s   00:00    thin server (0.0.0.0:3204)_2015-08-15.log                                                                           100%   46KB  46.1KB/s   00:00    thin server (0.0.0.0:3205)_2015-08-15.log                                                                           100%   43KB  43.4KB/s   00:00    thin server (0.0.0.0:3206)_2015-08-15.log                                                                           100%   46KB  45.7KB/s   00:00    thin server (0.0.0.0:3207)_2015-08-15.log                                                                           100%   44KB  44.5KB/s   00:00    thin server (0.0.0.0:3208)_2015-08-15.log                                                                           100%   44KB  43.6KB/s   00:00    nginx.access.20150815.log                                                                                           100%   81MB   4.3MB/s   00:19    nginx.access.20150815.log                                                                                           100%   81MB   4.1MB/s   00:20    nginx.access.20150815.log                                                                                           100%   81MB   2.7MB/s   00:30

 

 

(2)分析日志

分析日志的脚本如下:

#!/usr/bin/env bashif [[ $1 == "--debug" ]]; then  set -xfiLOG_PATH=~/Documents/logs/8-15TMP_FILE=/tmp/analyse_cat.logtv() {  project=$1  log_files=$LOG_PATH/$project/**/*.log  for hour in {15..16}; do    for min in {0..5}; do      if [[ $hour -lt 10  ]]; then        str="2015-08-15 0$hour:$min"      else        str="2015-08-15 $hour:$min"      fi        request_count=$(grep "$str" $log_files | wc -l)      response_count=$(grep "^$hour:$min" $log_files | grep Completed | wc -l)      grep "^$hour:$min" $log_files | grep Completed > $TMP_FILE      echo "------- $str 时总请求数: $request_count,响应数:$response_count"      echo '响应码:'      cut -d ' ' -f4 $TMP_FILE | sort -n | uniq -c      # echo '响应时间:'      # cut -d ' ' -f7 $TMP_FILE | sort -n | uniq -c | sort -nr    done  done}echo '*** Youku TV ***'tv m-cms-for-tvecho '*** Tubou TV ***'tv m-cms-for-tudou-tv

执行

$ ./analyse_log

执行后的结果

~/Desktop:$ ./analyse_log *** Youku TV ***------- 2015-08-15 15:0 时总请求数: 10934,响应数:10934响应码:  10934 200------- 2015-08-15 15:1 时总请求数: 10908,响应数:10908响应码:  10908 200------- 2015-08-15 15:2 时总请求数: 10903,响应数:10903响应码:  10903 200------- 2015-08-15 15:3 时总请求数: 7184,响应数:7160响应码:   7160 200------- 2015-08-15 15:4 时总请求数: 552,响应数:0响应码:------- 2015-08-15 15:5 时总请求数: 194063,响应数:193978响应码: 193978 200------- 2015-08-15 16:0 时总请求数: 142234,响应数:142233响应码: 142233 200------- 2015-08-15 16:1 时总请求数: 195244,响应数:195244响应码: 195244 200------- 2015-08-15 16:2 时总请求数: 233320,响应数:233342响应码: 233342 200------- 2015-08-15 16:3 时总请求数: 12787,响应数:12788响应码:  12788 200------- 2015-08-15 16:4 时总请求数: 11341,响应数:11341响应码:  11341 200------- 2015-08-15 16:5 时总请求数: 12470,响应数:12470响应码:  12470 200*** Tubou TV ***------- 2015-08-15 15:0 时总请求数: 5,响应数:5响应码:      5 200------- 2015-08-15 15:1 时总请求数: 3,响应数:3响应码:      3 200------- 2015-08-15 15:2 时总请求数: 39,响应数:39响应码:     39 200------- 2015-08-15 15:3 时总请求数: 11,响应数:3响应码:      3 200------- 2015-08-15 15:4 时总请求数: 31,响应数:0响应码:------- 2015-08-15 15:5 时总请求数: 1315,响应数:1288响应码:   1288 200------- 2015-08-15 16:0 时总请求数: 9,响应数:9响应码:      9 200------- 2015-08-15 16:1 时总请求数: 2,响应数:2响应码:      2 200------- 2015-08-15 16:2 时总请求数: 39,响应数:39响应码:     39 200------- 2015-08-15 16:3 时总请求数: 10,响应数:10响应码:     10 200------- 2015-08-15 16:4 时总请求数: 2,响应数:2响应码:      2 200------- 2015-08-15 16:5 时总请求数: 15,响应数:15响应码:     15 200

 

转载于:https://www.cnblogs.com/iwangzheng/p/4764023.html

你可能感兴趣的文章
MonoDB的数据准备
查看>>
tomcat和servlet关系
查看>>
深入理解java虚拟机,内存管理部分
查看>>
【转】一个lucene的官网例子
查看>>
Knockout2.x:ko.dataFor()、ko.contextFor()使用
查看>>
产品经理专业术语
查看>>
mysql常用语法
查看>>
HDU 1728 逃离迷宫(DFS经典题,比赛手残写废题)
查看>>
面向过程VS面向对象的理解
查看>>
iPhone中png图片格式处理(附:linux下alias命令详解)
查看>>
Iphone开发问题集
查看>>
php实现一致性hash算法
查看>>
docker使用命令
查看>>
VGA、DVI、HDMI、DP 接口介绍及优劣
查看>>
从19本书中选取五本,并且要求这五本互相不相邻,一共有多少种方法?
查看>>
ubuntu16.04 caffe(GPU模式)安装
查看>>
批处理+VBS+注册表实现开机自动启动EXE程序
查看>>
Python爬虫之设置selenium webdriver等待
查看>>
测试用例编写思路
查看>>
R语言与Tableau集成之可视化应用
查看>>