本文主要面向新浪云存儲(chǔ)服務(wù)的開(kāi)發(fā)者,開(kāi)發(fā)者可通過(guò)此文學(xué)習(xí)如何使用新浪云存儲(chǔ)進(jìn)行開(kāi)發(fā)
訪問(wèn)日志每行為一條記錄。每個(gè)日志記錄代表一個(gè)請(qǐng)求,每個(gè)字段用空格分隔。下面是一個(gè)示例,包含兩條日志記錄。
SINA000000ABCDEFGHIJ my-bucket [29/Aug/2014:20:23:12 +0800] 111.161.68.74 GRPS000000ANONYMOUSE 000a2709-1408-2920-2312-782bcb67c7d1 REST.GET.OBJECT /path/to/file "GET /my-bucket/path/to/file HTTP/1.1" 304 - 0 4510 28 27999 "http://edu.sina.com.cn/a/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" - SINA000000ABCDEFGHIJ my-bucket [29/Aug/2014:20:23:12 +0800] 111.161.68.74 GRPS000000ANONYMOUSE 000a2709-1408-2920-2312-782bcb67c7d9 REST.GET.OBJECT /path/to/file/xx "GET /path/to/file/xx HTTP/1.1" 404 NoSuchBucket 0 4510 28 27999 "http://foo.com/a" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" -
任何字段可以被設(shè)置為“ - ”,表示該數(shù)據(jù)是未知的或沒(méi)有值,或者該字段并不適用于這一請(qǐng)求。
字段描述:
字段 | 舉例 | 描述 |
---|---|---|
Bucket Owner | SINA000000ABCDEFGHIJ | bucket所有者的userid |
Bucket | my-bucket | 當(dāng)前請(qǐng)求的bucket名 |
Time | [29/Aug/2014:20:23:12 +0800] | 服務(wù)器接收到當(dāng)前請(qǐng)求的時(shí)間,格式:[%d/%b/%Y:%H:%M:%S %z] |
Remote IP | 111.161.68.74 | 客戶端ip地址 |
Requester | GRPS000000ANONYMOUSE | 請(qǐng)求者的身份(user_id或者group_id) |
Request ID | 000a2709-1408-2920-2312-782bcb67c7d1 | 云存儲(chǔ)服務(wù)器端生成的每個(gè)請(qǐng)求的唯一標(biāo)示 |
Operation | REST.PUT.OBJECT | 操作標(biāo)示:REST.HTTP_method.resource_type |
Key | /path/to/file | object的key |
Request-URI | "GET /my-bucket/path/to/file HTTP/1.1" | HTTP請(qǐng)求的描述 |
HTTP status | 200 | HTTP響應(yīng)碼 |
Error Code | NoSuchBucket | 錯(cuò)誤碼,如果沒(méi)有錯(cuò)誤,用“ - ”占位 |
Bytes Sent | 2662992 | 服務(wù)器端響應(yīng)的數(shù)據(jù)大小(下行),單位:bytes |
Object Size | 3462992 | Object的大小,單位:bytes |
Total Time | 70 | 從服務(wù)器收到請(qǐng)求,到響應(yīng)結(jié)束的總時(shí)間,單位:milliseconds(毫秒) |
Turn-Around Time | 10 | 從服務(wù)器收到請(qǐng)求,到開(kāi)始響應(yīng)的時(shí)間(不包括下載的時(shí)間),單位:milliseconds(毫秒) |
Referrer | "http://edu.sina.com.cn/a/" | 當(dāng)前請(qǐng)求的來(lái)源,依賴于瀏覽器發(fā)送的:HTTP Referrer header |
User-Agent | "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" | 發(fā)出請(qǐng)求的客戶端的User-Agent |
Version Id | 3HL4kqtJvjVBH40Nrjfkd | 暫時(shí)沒(méi)有具體含義,一般情況下用“ - ”占位 |
日志解析示例:
function parse_log($log) {
$pattern = '/(?P<owner>\S+) (?P<bucket>\S+) (?P<time>\[[^]]*\]) (?P<ip>\S+) (?P<requester>\S+) (?P<reqid>\S+) (?P<operation>\S+) (?P<key>\S+) (?P<request>"[^"]*") (?P<status>\S+) (?P<error>\S+) (?P<bytes>\S+) (?P<size>\S+) (?P<totaltime>\S+) (?P<turnaround>\S+) (?P<referrer>"[^"]*") (?P<useragent>"[^"]*") (?P<version>\S)/';
$match = preg_match($pattern, $log, $matches);
if ($match && is_array($matches) && count($matches) > 0) {
foreach ($matches as $key => $value) {
if ($value == '-' || $value == '"-"') $matches[$key] = '';
if (is_numeric($key)) unset($matches[$key]);
}
return $matches;
}
return false;
}
$log = 'SINA000000ABCDEFGHIJ my-bucket [29/Aug/2014:20:23:12 +0800] 111.161.68.74 GRPS000000ANONYMOUSE 000a2709-1408-2920-2312-782bcb67c7d1 REST.GET.OBJECT /path/to/file "GET /my-bucket/path/to/file HTTP/1.1" 304 - 0 4510 28 27999 "http://edu.sina.com.cn/a/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" -';
$parse = parse_log($log);
print_r($parse);