127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/login?aid=6&clientver=20160107&gid=F35DA66BB5EFB4F2FA5A8DF9A0DA2E8E&time=145913 5036&value=ABCDEGSHIOEHIE1534876457EWQERQ42&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.017"
127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/pat?rid=51457573427 HTTP/1.1" 200 1068 " -" "-" - "0.017"
127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ &time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd =4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.021"
127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid= 5&clientver=20160107&gid=4897654WQERWQWRRRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQ WEW HTTP/1.1" 200 38 "-" "-" - "0.018"
127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 174 "-" "-" - "0.043"
127.0.0.1 - - [28/Mar/2016:11:23 :14 +0800] 「POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1 .1" 200 66 "-" "-" - "0.035"
127.0.0.1 - - [28/ Mar/2016:11:23:14 +0800] "POST /abc/a1/img?aid=5&clientver=20160107&gid=4897654WQERWQWRRRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8 E532D2D18&sid=59&rid=41897423418&imgname=101_20160104_105657_733%20-%20%E5%89%AF% E6%9C%AC.jpg HTTP/1.1" 200 67 "-" "-" - "0.115"
127.0.0.1 - - [28/Mar/2016:11:23:15 +0800] "GET /abc/a1 /end?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135378&value=9C59B861AE0AB2C6BB9DEC8819AE1015&sid=59&rid=41897423418 HTTP/1.1 " 200 38 "-" "-" - "0.136"
どのように解析类似以上日志文件分别获得四个接口(ログイン, post、img、end )毎分成功数、毎分失敗数、および毎分平均の応答時間
日志格式の最終的な応答時間は、例えば:0.136 です。
逆承認 (解決策)
$log =<<< TXT127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/login?aid=6&clientver=20160107&gid=F35DA66BB5EFB4F2FA5A8DF9A0DA2E8E&time=1459135036&value=ABCDEGSHIOEHIE1534876457EWQERQ42&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.017"127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/pat?rid=51457573427 HTTP/1.1" 200 1068 "-" "-" - "0.017"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.021"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.018"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 174 "-" "-" - "0.043"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 66 "-" "-" - "0.035"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/img?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&sid=59&rid=41897423418&imgname=101_20160104_105657_733%20-%20%E5%89%AF%E6%9C%AC.jpg HTTP/1.1" 200 67 "-" "-" - "0.115"127.0.0.1 - - [28/Mar/2016:11:23:15 +0800] "GET /abc/a1/end?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135378&value=9C59B861AE0AB2C6BB9DEC8819AE1015&sid=59&rid=41897423418 HTTP/1.1" 200 38 "-" "-" - "0.136"TXT;foreach(preg_split("/[\r\n]+/", $log) as $row) { $t = explode(" ", $row); @$res[date('Y-m-d H:i', strtotime(substr($t[3].' '.$t[4], 1, -1)))][basename(parse_url($t[6])['path'])]++;}print_r($res);
Array( [2016-03-28 11:17] => Array ( [login] => 1 [pat] => 1 ) [2016-03-28 11:23] => Array ( [login] => 2 [post] => 2 [img] => 1 [end] => 1 ))
を使用して、その後、分析を行うことができます。
$log =<<< TXT127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/login?aid=6&clientver=20160107&gid=F35DA66BB5EFB4F2FA5A8DF9A0DA2E8E&time=1459135036&value=ABCDEGSHIOEHIE1534876457EWQERQ42&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.017"127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/pat?rid=51457573427 HTTP/1.1" 200 1068 "-" "-" - "0.017"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.021"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.018"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 174 "-" "-" - "0.043"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 66 "-" "-" - "0.035"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/img?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&sid=59&rid=41897423418&imgname=101_20160104_105657_733%20-%20%E5%89%AF%E6%9C%AC.jpg HTTP/1.1" 200 67 "-" "-" - "0.115"127.0.0.1 - - [28/Mar/2016:11:23:15 +0800] "GET /abc/a1/end?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135378&value=9C59B861AE0AB2C6BB9DEC8819AE1015&sid=59&rid=41897423418 HTTP/1.1" 200 38 "-" "-" - "0.136"TXT;foreach(preg_split("/[\r\n]+/", $log) as $row) { $t = explode(" ", $row); @$res[date('Y-m-d H:i', strtotime(substr($t[3].' '.$t[4], 1, -1)))][basename(parse_url($t[6])['path'])]++;}print_r($res);
Array( [2016-03-28 11:17] => Array ( [login] => 1 [pat] => 1 ) [2016-03-28 11:23] => Array ( [login] => 2 [post] => 2 [img] => 1 [end] => 1 ))
恩恩、谢谢!大神我想统计这一分間平均响应時間,我该どのように实现呢?要である自動脑筋の
响应時間期間は哪项?
加起来除以条数
是是最后的那个数字第一条0 .017
$log =<<< TXT127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/login?aid=6&clientver=20160107&gid=F35DA66BB5EFB4F2FA5A8DF9A0DA2E8E&time=1459135036&value=ABCDEGSHIOEHIE1534876457EWQERQ42&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.017"127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/pat?rid=51457573427 HTTP/1.1" 200 1068 "-" "-" - "0.017"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.021"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.018"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 174 "-" "-" - "0.043"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 66 "-" "-" - "0.035"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/img?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&sid=59&rid=41897423418&imgname=101_20160104_105657_733%20-%20%E5%89%AF%E6%9C%AC.jpg HTTP/1.1" 200 67 "-" "-" - "0.115"127.0.0.1 - - [28/Mar/2016:11:23:15 +0800] "GET /abc/a1/end?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135378&value=9C59B861AE0AB2C6BB9DEC8819AE1015&sid=59&rid=41897423418 HTTP/1.1" 200 38 "-" "-" - "0.136"TXT;foreach(preg_split("/[\r\n]+/", $log) as $row) { $t = explode(" ", $row); $k = date('Y-m-d H:i', strtotime(substr($t[3].' '.$t[4], 1, -1))); @$res[$k][basename(parse_url($t[6])['path'])]++; $res[$k]['avg'][] = trim(end($t), '"'); //新增}foreach($res as &$v) $v['avg'] = array_sum($v['avg']) / count($v['avg']); //新增print_r($res);
Array( [2016-03-28 11:17] => Array ( [login] => 1 [avg] => 0.017 [pat] => 1 ) [2016-03-28 11:23] => Array ( [login] => 2 [avg] => 0.061333333333333 [post] => 2 [img] => 1 [end] => 1 ))
$log =<<< TXT127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/login?aid=6&clientver=20160107&gid=F35DA66BB5EFB4F2FA5A8DF9A0DA2E8E&time=1459135036&value=ABCDEGSHIOEHIE1534876457EWQERQ42&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.017"127.0.0.1 - - [28/Mar/2016:11:17:33 +0800] "GET /abc/a1/pat?rid=51457573427 HTTP/1.1" 200 1068 "-" "-" - "0.017"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.021"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "GET /abc/a1/login?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&pwd=4897654897486489WERQER487WEEQWEW HTTP/1.1" 200 38 "-" "-" - "0.018"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 174 "-" "-" - "0.043"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/post?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18 HTTP/1.1" 200 66 "-" "-" - "0.035"127.0.0.1 - - [28/Mar/2016:11:23:14 +0800] "POST /abc/a1/img?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135377&value=5913350E12FE86E07E794E8E532D2D18&sid=59&rid=41897423418&imgname=101_20160104_105657_733%20-%20%E5%89%AF%E6%9C%AC.jpg HTTP/1.1" 200 67 "-" "-" - "0.115"127.0.0.1 - - [28/Mar/2016:11:23:15 +0800] "GET /abc/a1/end?aid=5&clientver=20160107&gid=4897654WQERWQWRRWRERASDW595564WQ&time=1459135378&value=9C59B861AE0AB2C6BB9DEC8819AE1015&sid=59&rid=41897423418 HTTP/1.1" 200 38 "-" "-" - "0.136"TXT;foreach(preg_split("/[\r\n]+/", $log) as $row) { $t = explode(" ", $row); $k = date('Y-m-d H:i', strtotime(substr($t[3].' '.$t[4], 1, -1))); @$res[$k][basename(parse_url($t[6])['path'])]++; $res[$k]['avg'][] = trim(end($t), '"'); //新增}foreach($res as &$v) $v['avg'] = array_sum($v['avg']) / count($v['avg']); //新增print_r($res);