在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
解析log: wget https://gist.githubusercontent.com/clanchun/2b5e07cda53718ccbf64f62fb31900c8/raw/64be7f018973717dd5faa7be2bfb817f50ed05bb/access.log package main import ( "bufio" "io" "os" "fmt" "regexp" "strings" ) var ( filePath string logReg = `TCP_HIT/([0-9][0-9][0-9]) [0-9]+ [A-Z]+ http://c13.adrise.tv/04C0BF/v2/sources/content-owners/[0-9a-z]+/([0-9]+)/` logMap = make(map[string]int) ) func init() { filePath =os.Args[1] } func processLog(contents string) { re := regexp.MustCompile(logReg) matches := re.FindAllStringSubmatch(contents, -1) for _, m := range matches { key := m[1]+ "_" +m[2] count, ok := logMap [ key ] if (ok) { logMap [ key ] = count + 1 } else { logMap [ key ] = 1 } } } func readLine(fileName string, handler func(string)) error { f, err := os.Open(fileName) if err != nil { return err } buf := bufio.NewReader(f) for { line, err := buf.ReadString('\n')
|
请发表评论