Example #1
0
func main() {
	p := parser.NewEngine(os.Stdin)
	records := p.GetRecords()

	res := map[string]map[string]map[string]int{}
	for _, record := range records {
		rl, ok := record.(nginx.RequestLine)
		if !ok {
			continue
		}
		status := fmt.Sprintf("%d", rl.ResponseStatus())
		method := rl.RequestMethod()
		u := rl.RequestURI()
		path := u
		pu, err := url.Parse(u)
		if err == nil {
			path = pu.Path
		}
		if _, ok := res[status]; !ok {
			res[status] = map[string]map[string]int{}
		}
		if _, ok := res[status][method]; !ok {
			res[status][method] = map[string]int{}
		}
		res[status][method][path]++
	}
	js, err := toJSON(res)
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: %s", err)
		os.Exit(1)
	}
	fmt.Fprintf(os.Stdout, "\n%s\n", js)
}
Example #2
0
func main() {
	p := parser.NewEngine(os.Stdin)
	for {
		select {
		case line := <-p.LogLines():
			if line != nil {
				fmt.Fprintf(os.Stdout, "%s\n", line)
			}
		case <-p.Dying():
			return
		}
	}
}
Example #3
0
func getReferrers(in io.Reader) map[string]int {
	p := parser.NewEngine(in)
	referrers := map[string]int{}
	for {
		select {
		case line := <-p.LogLines():
			if line != nil {
				if rl, ok := line.(nginx.RequestLine); ok {
					referrer := rl.RequestHTTPReferrer()
					if referrer == "-" {
						continue
					}
					if u, err := url.Parse(referrer); err == nil {
						referrers[u.Scheme+"://"+u.Host]++
					} else {
						referrers[referrer]++
					}
				}
			}
		case <-p.Dying():
			return referrers
		}
	}
}