qq_php开发者_0
不知道
慕村1538275
2019/07/24 21:53:03 ParseInLocation fail: parsing time "[24/Jul/2019:21:53:03 +0000]" as "02/Jan/2006:15:04:05 +0000": cannot parse "[24/Jul/2019:21:53:03 +0000]" as "02" [24/Jul/2019:21:53:03 +0000]
ret[4]打印出来是这个 [24/Jul/2019:21:53:03 +0000]
SXT加油
使用指针可以避免数据的拷贝并且能直接修改原来的数据
许安强
已解决
再相信一次
慕勒3157497
阿諾同学
你这个明显是influxdb没有安装呀~
thur
//nginx规则
'$remote_addr\t$http_x_forwarded_for\t$request\t$status\t$body_bytes_sent\t$bytes_sent\t$http_user_agent\t$request_length\t$request_time\t$time_local\t$upstream_response_time'
/**
解析模块
*/
func (l *LogProcess) Process() {
/*rege := regexp.MustCompile(`([\d\.]+)\s+([^ \[]+)\s+([^ \[]+)\s+\[([^\]]+)\]\s+([a-z]+)\s+\"([^"]+)\"\s+(\d{3})\s+(
\d+)\s+\"([^"]+)\"\s+\"(.*?)\"\s+\"([\d\.-]+)\"\s+([\d\.-]+)\s+([d\.-]+)`) //解析正则表达式*/
//循环解析
loc, _ := time.LoadLocation("Asia/Shanghai");
for v := range l.rc {
//res := rege.FindStringSubmatch(string(v) )
fmt.Println(string(v))
res := strings.Split(string(v), "\t")
if len(res) != 11 { //匹配失败
log.Println("rege.FindStringSubmatch fail: ", string(v), len(res)) //写日志
continue
}
message := &Message {}
//时间
theTime, err := time.ParseInLocation("02/Jan/2006:15:04:05 +0800", res[9], loc) //解析时间
if err != nil {
log.Println("time.ParseInLocation fail: ", err.Error(), res[9]) //写日志
continue
}
time := theTime.Unix()
message.TimeLocal = time
bytesSent, _ := strconv.Atoi(res[5]) //字符串转 int
message.BytesSent = bytesSent
//"POST /API/COURSE/INDEX HTTP/1.1"
resSli := strings.Split(res[2], " ") //字符串分割
if len(resSli) != 3 {
log.Println("strings.Split fail", res[2]) //写日志
continue
}
message.Method = resSli[0]
resUrl, err := url.Parse(resSli[1])
if err != nil {
log.Println("url.Parse fail", err.Error(),resSli[1]) //写日志
continue
}
message.Path = resUrl.Path
message.Scheme = resSli[2]
message.Status = res[3]
upstreamTime, _ := strconv.ParseFloat(res[10], 64)
message.UpstreamTime = upstreamTime
requestTime, _ := strconv.ParseFloat(res[8], 64)
message.RequestTime = requestTime
l.wc <- message
}
}
慕桂英9619482
正则没有匹配到,就会是空
慕桂英9619482
建议看一下nginx日志的具体解释 究竟是什么意思
绝地反击的故事
也可以在这里找到哦,https://github.com/itsmikej/imooc_logprocess
慕粉1958365020
你可以根据你的nginx配置来写正则,注意对应好每个字段
sd1700092
可以在这里找到源码,https://github.com/itsmikej/imooc_logprocess,主程序和mock都有~
幕幕0